I know it has to do with the data members but why is that good programming to do so? any examples why?
I know it has to do with the data members but why is that good programming to do so? any examples why?
"Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
-Bruce Lee
Encapsulation
To avoid other member functions/data members/classes to modify the data. Mainly used for data security.
Hope I'm right.
Can anyone second me?
Last edited by biosninja; 11-11-2002 at 06:08 PM.
That definitely makes sense once i think about it. I mean why would you want others messing around with your stuff.Originally posted by biosninja
Encapsulation
To avoid other member functions/data members/classes to mdify the data. Mainly used for data security.
Hope I'm right.
Can anyone second me?
Thnxs Ninja!
"Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
-Bruce Lee
Messing around with your stuff, indeed!
Programmers only need to know that the class works, not what goes on behind the scenes. There's no reason to allow anyone to "mess" with the data.
Easy way to turn a "class" into "trash".
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
O yeah.... That includes accessor functions - thats a special function that can actually access the data and or change it that is called out side of the class.....or something like that
Here's what I've been told about professional programming. Programs are divided up into modules. Separate teams work on separate modules. Those teams don't know how the other teams are doing what they need to do; they only know what others are supposed to do. How anything is achieved is irrelevant. In order to achieve the modularity and granularity necessary for programming large problems in an efficient manner, information hiding is necessary.
encapsulation
-----------------
Definition :
The restriction of knowledge to the scope of a module, i.e. data and implementation are encapsulated when the client can see only the service calls and no implementation details. Instance variables and methods can be added, deleted, or changed, but as long as the services provided by the object remain the same, code that uses the object can continue to use it without being rewritten.
I got this from : Definition