[Tutor] [Slightly OT] Inheritance, Polymorphism and Encapsulation
alan.gauld at btinternet.com
Wed Sep 19 09:17:21 CEST 2007
"Ricardo Aráoz" <ricaraoz at gmail.com> wrote>
> Encapsulation comes with OO - you get it for free.
> Encapsulation does not come with OO. It is something you must code
> your classes.
This depends on your definition of encapsulation.
Many modern texts use a definition of encapsulation that relates
to data hiding. Thus, making attributes private/protected etc is
encapsulation. This definition didn't start to appear till the very
80's with the rise of C++. In the early days of OOP encapsulation
was the act of binding data and functions together in a single code
entity - a class(*).
The early definition was a radical new idea in the 70's and 80's but
with the advent of OOP languages liker C++/Java it becomes a
fundamental concept so its easy to forget how important and
fundamental encapsulation of data and function into a class is.
It is literally the foundation of all Object Oriented and Object
Based programming. And without an OOP that kind of
encapsulation is very tricky to get right. Data hiding is a nice
to have. Python OOP provides the original concept of encapsulation
but doesn't really support the later meaning.
(*)BTW Its also possible to do OOP without classes! This is not
often seen nowadays but there were several OOP languages in
the 70's and 80's that explored that route. Scheme is probably
the best known. Its a very different kind of OOP of course but the
basic concepts are all there.
Author of the Learn to Program web site
More information about the Tutor