PDA

View Full Version : class concept


dion
September 25th, 2009, 23:02
i really don't know how to explain this properly, so sorry if it'll confuse you.

everyone knew class concept introduced since c++. as in my learning process in college, it's just really like a passing by, heard from left ear and gone out thru the right one. well, in at least i pass the exam. after some years, i still really can't grasp the class concept. i was once learn to code a visual component in delphi, which is using somekind of inheritance. from there i learn a bit about what kind of class, from delphi point of view.

a tale like, at first there is a code, and then there is a variable, then there is a class, well it just maybe. so, the class is somewhat providing a way to accomplish a task where a code and variable alone can do? or else?

i was always thought that OOP in game dev, should at least give a simple concept about how class concept is. i knew in delphi, class consists some vars and some functions. those functions then interact as it is a single object providing a common interface. it still blurry, as i don't really know why is there a class, should code and var alone can't do?

regards

BanMe
September 26th, 2009, 02:03
classes provide modularized behaviors to acomplish a task yes..
well classes arent really needed..so var and code works as well as a class which is code/var all put neatly coded together..so either works.

Daniel Pistelli
September 28th, 2009, 07:26
In theory you can write everything in assembly. =)

The point of classes is how you organize you code. Classes and templates save you from writing the same code more times, by inheriting a class you inherit certain behaviors, which you can also costumize by using virtual methods. You could do it all manually through structures and function pointers, but it would be a mess.

Similarly a template makes you re-use your code on different types. It all comes down to you, the dev, writing less code.

dion
September 28th, 2009, 11:08
thank you for the simple and direct answers.

i think i've forgotten the way to learn in this, because to answer right is somewhat more important than seeing why need those things, yes, a typical short minded (like me) would just have followed the lesson without questioning it, because the lesson itself somewhat boring.

actually, i took times to google and read about it, but still confused.

i just remembered seeing a c++ source code, that like i can see class everywhere. i thought myself, gee... why such a simple code become a class member?? and i thought... can't we really live without class??
well, maybe it just my impression. but i started to think people tend to forget the class purpose, and did even simple things with class.

but thanks again for the answer

Daniel Pistelli
September 28th, 2009, 13:03
C++ can be overused, that's true. It doesn't make much sense having a class if u just have one method in it with no class members.

Rememebr that C is used to write entire frameworks and operating systems. But try comparing the use of a char *str; string compared to a QString. You'll see the elegance of QString and even safety (no easy buffer overflows).

That said, it is up to you to decide what you need, but I hate to develop user mode code without objects.

Just consider the use of templates, which makes you save lots of efforts, let's say u need an array of a class of yours called "Contact".

List<Contact> mylist;
mylist.append(Contact("Mark Twain", Friend, Date(11, 02, 77)));

Now, do the same in C. You can technically, of course, but it will look very differently.