protocols, inheritance and polymorphism

Christophe Cavalaria chris.cavalaria at free.fr
Thu Nov 25 14:35:42 EST 2004


Jacek Generowicz wrote:

> "Dan Perl" <danperl at rogers.com> writes:
> 
>> Can you elaborate on problems that static languages have with OOP?
> 
> They make dynamic polymorphism impossible.
> 
> Which is why most object-oriented C++ programs are dynamically typed;
> only the programmer is burdened with the work that the mostly-absent
> dynamic type system should be doing.
> 
> Dynamic polymorphism crucially requires knowledge of the *run-time*
> (dynamic) type of objects, in order to be able to dispatch to the
> correct method. In C++ you turn your classes into dynamically typed
> ones with the "virtual" keyword, which introduces a vtable and
> run-time type identification (RTTI). As long as you are only
> interested in calling methods which are declared in some base class,
> this dynamic type systems looks almost satisfactory. As soon as you
> want to use a method present in the subclass but not in the
> superclass, it is up to you to faff around with dynamic_cast and
> checking of the resulting pointer; all stuff which a dynamic type
> system should be doing for you, but C++ makes you do yourself because
> it pretends that your programs are statically typed when, in fact,
> they are dynamically typed.
If your programs need that much dynamic_cast to work, then your programs are
bad. Besides, it's easy to do a 'safe' dynamic_cast, just assert that the
pointer you get isn't 0 after the cast.



More information about the Python-list mailing list