E
E. Robert Tisdale
Marshall Cline wrote:
http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.4
"Preventing unauthorized access
to some piece of information or functionality."
That's *data hiding* -- not encapsulation.
A C struct *encapsulates* data members
but C does not support any mechanism
for hiding the actual data representation
except *opaque* data structures.
"Inheritance can also be used as a form of encapsulation."
Yes, but public inheritance does not "hide" the base class.
"Designing a clean interface
and separating that interface from its implementation
merely allows users to use the interface.
But encapsulating (putting "in a capsule") the implementation
forces users to use the interface."
No. It does *not* force the "user" to use the interface.
A determined hacker will find a way to "reach around" the interface
and access the data members directly.
Data hiding is *not* encryption.
It merely prevents unwary application programmers
from *accidently* accessing data members directly.
http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.4
"Preventing unauthorized access
to some piece of information or functionality."
That's *data hiding* -- not encapsulation.
A C struct *encapsulates* data members
but C does not support any mechanism
for hiding the actual data representation
except *opaque* data structures.
"Inheritance can also be used as a form of encapsulation."
Yes, but public inheritance does not "hide" the base class.
"Designing a clean interface
and separating that interface from its implementation
merely allows users to use the interface.
But encapsulating (putting "in a capsule") the implementation
forces users to use the interface."
No. It does *not* force the "user" to use the interface.
A determined hacker will find a way to "reach around" the interface
and access the data members directly.
Data hiding is *not* encryption.
It merely prevents unwary application programmers
from *accidently* accessing data members directly.