Re: virtual fn, destructor
Martin Drautzburg <Martin.Drautzburg@web.de> writes:
Actually I'd say that subclassing is *the* primary thing in OO.
An object-oriented language does not need to have classes
or inheritance, but it needs run-time polymorphism (also
known as ?late binding?).
In my opinion, the main advantage is the possibility to extend
verbs without the need to change existing code. This supports
the open-closed principle for verbs. (I use ?verb? to mean
names of functions or operators here.)
A related feature of C++ is the possibility to overload ?<<?
for custom classes. In a procedural language, there only would
be one single procedure called ?operator <<?. To extend ?<<?
for another type, one would need to /modify/ this procedure
definition, which is error-prone or sometimes not possible (if
the definition is in a second-party library).
But, IIRC, in C++, ?<<? has static dispatch? Now imagine the
same thing with dynamic dispatch and you got what I believe to
be the core feature of an object- oriented language.
A similar opinion is:
?This is the heart of why ObjectOrientedProgramming is better.?
http://c2.com/cgi/wiki?ReplaceConditionalWithPolymorphism
~~
The term ?object-oriented programming? was coined by Alan Kay.
In 2003, I asked him, what it means and he kindly replied to me:
?OOP to me means only messaging, local retention and
protection and hiding of state-process, and extreme
late-binding of all things. It can be done in Smalltalk
and in LISP. There are possibly other systems in which
this is possible, but I'm not aware of them.?
http://www.purl.org/stefan_ram/pub/doc_kay_oop_en