PolymorphismEncapsulationInheritance
Last edit April 22, 2004
One of the classical
DefinitionsForOo
; one which is often accused of being
CeePlusPlus
centric. A language supports OO programming if it has:
Polymorphism; in this context this really means
SubtypePolymorphism
. As pointed out below, there are many other types.
Encapsulation; there are means to segregate an object's interface from its implementation. This may be enforced by the language (as in
CeePlusPlus
and
JavaLanguage
) or by convention (as in
PythonLanguage
and
CommonLispObjectSystem
)
Inheritance; reuse of base classes to form derived classes. Some object to this, as other mechanisms exist (interface inheritance, delegation, structural typing) to implement subtypes.
In most
ObjectOriented
Languages: Polymorphism = Encapsulation + Inheritance
But
InheritanceBreaksEncapsulation
.
Is
PolyMorphism
the reason for
ObjectOrientation
to exist?
No, OO exists because it's a convenient way to structure code and modularize programs. Polymorphism is a key benefit, but not the only one.
There are other ways to achieve Polymorphism, namely
ParametricPolymorphism
(STL =
StandardTemplateLanguage
) and Generics (
TheRightWayToImplementTemplates
).
Generics
are
ParametricPolymorphism
. While
JavaGenerics
and
CppTemplates
and
DynamicTyping
all go about it the same way; they all are ways of implementing
ParametricPolymorphism