Overriding (factory?) methods and inheritance ...

Rocco Rossi rockrossi69 at libero.it
Mon Dec 30 11:43:35 EST 2002


I posted a message yesterday about problems I was having when inheriting
from base classes that contained methods (would it be correct to call them
"factory" methods) which produced instances of the same class (type), like a
RationalNumber class or a ComplexNumber class or Vector class, and so on.

The inherited specialized class would of course have those same methods
return values of the base class type, so that in the end one would not be
able to exploit the new features of the inherited class for those values ...
no code re-use!!!

One way out, of course, (which was also suggested by Laotseu --- BTW
thanks ---), would be to override precisely those methods, and like I said,
we would be losing the benefits of object-oriented programming that way, but
it certainly still is possible to let the base class do the majority of the
work ... Has this problem ever come up before? It seems to me that it is
non-trivial, but then again maybe I'm not confronting it in the appropriate
manner. Need some help.

Thanks.






More information about the Python-list mailing list