-
Why Classes??
I have read about using Class But I doesn't understand Why to use Class??
I mean if I will creat a Class that contain 2 funcs and 5 varibles
what will be worse if I creat 2 func and 5 varibles outside a class
and not useing class???
[ I does not refuse using Classes But doesn't understand Why?]
-
Because classes help you see programming-type problems in a "real world" way - for example, it is more "natural" to have an account object in a banking application that handles it's own withdrawal and deposit methods than to have that code scattered around in various places. Also, classes encapsulate, or hide code from a user of the class, so that in theory it is easy to upgrade the code for a class without "breaking" the code that uses it.
(IMHO)
-
Because if you 'write' a class to do a specific task(such calculate the surface of a circle) and you need it someday in another project, well the class you've wrtie will work in any programs.... if you don't do it in a class, well you'll have to re-write everything to make it fit into your program....
a class is reusable...
-
....and if you write it properly, to allow you to inherit it, to allow you to use it to calculate the area of a square, or rhomboid, or whatever.
-
One nice thing is that you can do this:
Code:
class c {
int anint;
char array[50];
void func();
int func2(int a);
};
//and then do
c classarray[50];
//instead of creating 50 of each variable and function