Why do they need to create Class?
What is useful to create Class?
Your help will be appreciated
Thank!!!!!!!!!!
Printable View
Why do they need to create Class?
What is useful to create Class?
Your help will be appreciated
Thank!!!!!!!!!!
There are many reasons to use classes.
1) It makes your system more structured. You can group methods, functions, constants, ... with a common goal.
2) It improves your flow of thoughts, because a class can be an entity: for example a class Person, which holds the name and address of a person or you can have a class BusinessProcess, which holds a length in hours, the envolved employers, ... But you can create just any class you like.
3) Data-classes can reflect the structure of your database.
4) A certain class can be designed without having knowledge of the other classes. This makes it easier to design the software in team.
5) It makes your system loosely coupled and therefor more flexible. That is, because a class hides all the details and keeps them for itself. So, when you choose to use a different technology you can just replace that 1 single class without having to rewrite your entire system.
6) Classes allow inheritance and polymorphism (for that you should follow a tutorial or so, that's too hard to explain here.
It is maybe handy to point out that classes can be categorized in 3 groups:
- data related classes: such as Person, Job, Car, Organization, Order, Bank, Delivery, Product, ...
- graphical related classes: such as Button, TextBox, Form, CheckBox, PictureBox, ...
- controller classes: these are classes which take care of the operation, communication and interaction between the different components of your system: such as DatabaseConnection, SelectionManager, Webcam, Thread, ...
If you want more, just read a book, or an online tutorial or check out wikipedia.
Class in the building block of Object-Oriented programing language, more easily structured the program. Easy to develop, easy to understand, etc...
Other than all that was said, designing with OOP in general makes it easier to relate to your customer/manager/anybody non-technical what you are doing since you are modeling your design off classes which will represent objects etc.
From my experience, while learning, structured programming was easier than object oriented. I couldn't understand why they were saying that OOP was easier since structured seemed easier. However now that I know OOP, I could definitely say that it is easier than structured, since it produces high quality structured programs that more manageable especially with maintenance.
With structured programming, one could easily sit down and start typing code. However with OOP, you actually have to plan your class diagrams initially (which seems more difficult), but after, everything runs smoothly.
Jennifer.
"procedural", perhaps?Quote:
Originally Posted by JenniferBabe
A difference of terminology. I guess it means the same. When we refer to structured programming, the style is that is the language C where a line of code executes one after the other from begin to end.
Probably a term of the caribbean (where i'm from) perhaps.
But all code executes from beginning to end. :D
No, structured programming is a valid term it just a bit 'old'. Looking at the history you will see the origins of OOP come out of structured programming.Quote:
Originally Posted by JenniferBabe
http://en.wikipedia.org/wiki/Structured_programming
Correct. Most of the OOP concepts are based on structured programming languages.Quote:
Originally Posted by superbovine
I agree the OOP came out of structured programming. What I was saying was for me I learnt structured first without OOP. The transition to OOP was like a big jump. During that transition OOP seemed more difficult, but after I learnt it OOP is a lot better.
Well maybe my last answer was more about Object Oriented programming than about classes. In this post I'll try to show a bit what classes are about and what the most obvious advantage is.
Without classes you would write the following:
in a Object oriented language you can write the code above better structured, by creating a class "Person" first, and writing the following:Code:Dim person1_Age As Integer
Dim person1_FirstName As String
Dim person1_Function As String
Dim person2_Age As Integer
Dim person2_FirstName As String
Dim person2_Function As String
person1_Age = 22;
person1_FirstName = "Bram";
person1_Function = "Director";
person2_Age = 19;
person2_FirstName = "Tom";
person2_Function = "Village Idiot";
You can also create a "constructor" to the class so that the creation is easier.Code:Dim person1 As Person
Dim person2 As Person
person1.Age = 22
person1.FirstName = "Bram"
person1.Function = "Director"
person2.Age = 19
person2.FirstName = "Tom"
person2.Function = "Village Idiot"
So, it's better structured because fields, properties, functions, events, ... are grouped together.Code:Dim person3 As Person
person1 = New Person("Paul", "CEM", 54)
Because they are grouped you can more easily pass them to functions, put them in lists, or save them to files, ...
But as I said earlier you can also put functions inside the classes. An example of how to use a function which was stored inside a class:Code:SavePersonToFile(person1, "somefile.txt") //is easy to read
SavePersonToFile(person1_firstname, person1_age, person1_job, "somefile.txt) //is harder to read
as for the saving to files, also this gets very clean!Code:Dim workedHours as Integer
workedHours = 45
Dim payCheck as Integer
payCheck = person1.CalculatePayCheck(workedHours)
For me personally this was the first advantage that opened my eyes and made me appreciate OOP. :). (Allthough strictly seen there are languages who support this and still are no real object oriented languages.)Code:person1.SaveToFile("somefile.txt")
Actually I feel this few years back. Fist of all I start to learn programming with C++, then move Java. There is a big gap, I fell, on OOP and structured programming. After few weeks feel easy to learn, easy to use any OOP language. Just need to get the correct idea about OOP concepts.Quote:
Originally Posted by JenniferBabe
And also you can use those groups again and again, in more cases.Quote:
Originally Posted by BramVandenbon
There are many Ideas on this OOP question.
Surely, you will see when you try to develop a project that related to Business. that need to separate Business from the programing.
So, the OOP is the way to separate Business logic from you program.
You easy to manage your group to develop that project.
For example, after you defined a class or a template that follow your business logic. it will become the standard for your process.
if other developer want to use this class in the same perspective, they can use existing class without re-code or they can extend by Inherits from the base class.