when to use classes
-
-
Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?
Archer282 wrote: So can anyone give me some examples of when it would be better to use a class? When you have more than 20 lines of code, you should be using classes. Either you're writing incredibly small and simple programs, or your code is a complete nightmare from a maintenence standpoint. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Archer282 wrote: So can anyone give me some examples of when it would be better to use a class? When you have more than 20 lines of code, you should be using classes. Either you're writing incredibly small and simple programs, or your code is a complete nightmare from a maintenence standpoint. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
After writing and erasing two lengthy replies (covering the history and philosophy of OO design) i see the merit in your reply. You are very wise. Although, i personally would have said 42 lines ... 42 being THE answer and all. :) ...cmk Save the whales - collect the whole set
-
Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?
I've been given this fantasitc new 13mm wrench. I know how to use it, but have only done so with 13mm nuts. How do i use it to build a car ? I don't mean to be flipant, but the question begs a reply that covers the whole of the object oriented design paradigm. A topic too large to fit in a reply. Start by reading up on object oriented design. Follow up by taking some small procedural programs you may have written and see if you can port some of the code into classes. The trick is to start seeing your program designs as the interaction of objects, as opposed to the paths of code execution. Wherever you see an 'object', you have a class waiting to be born. ...cmk Save the whales - collect the whole set
-
Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?
When to use Classess? What type of classes do u want to use. Ok whenever u want to do some socket programming then u have to derive it from socket class. Everything is depend on the situation. Thats is a other matter that u want to go for classes or not. But OO provides the class concept which is one of the beautiful thing. Neelesh Jain. Work Hard and A Bit of LUCK is KEY to SUCCESS.
-
Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?
You use classes to "group" logical pieces of code together. example: You have a class car. This class has several properties like maximum speed, color, type, ... and this car can do stuff like drive, turn right and (hopefully) left, brake, ... now typically your properties are your variables; so you would have a string type, double maxspeed, string color, ... The things your class can do are your functions. so void Drive(){ ... }, void TurnLeft(){...} and so on. So far your with me I hope. Now if you've encapsulated your class you can call this class somewhere else. So you make another class like racetrack in this class you can call as many instances of your carclass as you like. each instance with his own properties... so in ractrack you declare: Car Porsche = new Car(); Car Volvo = new Car(); .... now you can set properties: Porsche.MaxSpeed = 320; // km/h Volvo.MaxSpeed = 160; // km/h (note: you have to know you public/private/protected...) this is just a simple example, but I hope I've made it a bit more clear for you. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
-
After writing and erasing two lengthy replies (covering the history and philosophy of OO design) i see the merit in your reply. You are very wise. Although, i personally would have said 42 lines ... 42 being THE answer and all. :) ...cmk Save the whales - collect the whole set
ROTFL - brilliant. I can't wait to hear the new HHGTTG episodes. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder