C++ Information Hiding, Abstraction, Access Specifiers
Hey guys,
I'm a beginner at C++ programming and can't seem to progress past classes and objects.
I get the concept about classes.
It is a blue print or design for something. But we can't use classes as we can;'t use a design for a car..we have to breathe life into it so therefore we instantiate a class to create an object.
Encapsulation, I understand is grouping data members and functions in a class.
But, what I don't understand is the use of access modifiers or in fact information hiding. What does it mean to hide information?
I can have 100m lines of code and I give it to a "user" which I understand as another programmer and not end user. the user can still see the code or blueprint of the class so we are not really hiding anything are we, the other programming has eyes!?
Or maybe that other classes or functions can't see the data members, which doesn't make sense to me. The compiler or class isn't going to say "hey there! class Animal has data member height of a value of 5! let me change it to 19 instead! Lol it doesn't make sense to me - another class or a compiler isn't bloody Skynet! haha
for example i have a class.
Code:
class Animal
{
public:
void setTypeOfAnimal() ;
void getTypeOfAnimal() ;
private:
int height, weight;
string type;
}
when I instantiate the class,
Code:
Animal Dog; Dog.height = 100 ;
i have to use a function to do it for me!
Code:
Dog.setTypeOfAnimal()
What is the point? it is essentially the same result at then end.
Can anyone please explain all this for me and with practical examples in your work why you think it is important to hide info or what hiding data means. and also with practical code. And when you write the code can you please make it well indented. I haven't done any C++ coding with classes - just learning the theory - so it will put me off.
If you want to give me a definition, please don't I can read the damn book which is useless to me.
Also what IS abstraction. It sounds to me like encapsulation or "data hiding".
Please help me!
Eman