(Newbie) Restricting inherited methods to operate on element from same subclass

andy2O at hotmail.com andy2O at hotmail.com
Mon Mar 14 15:08:23 EST 2005


Bruno Desthuilliers wrote:
> You've already got the technical answer. About a possible design
flaw,
> it would seem to me that restricting the join() operation on specific

> subclasses breaks the LSP. OTOH, Python being dynamically typed,
> inheritence is merely an implementation detail, so that may not be
such
> a big deal after all... Anyway, you may want to document this point
to
> make it clear for the next person that'll have to work this code.
>
> My 2 cents

OK, thanks - I see your point.

I was in effect implementing mutable objects, similar in some sense to
lists, by extending an immutable class similar to Python's tuples. I
think instead I should copy the Python type hierarchy, with the
list-like and tuple-like classes each defined as sub-classes of a
'sequence' class. In this case the type checking could go away.

I'm learning object-orientated programming and dynamic typed languages
the hard way at the moment, by trial and error. Can you, or anyone
suggest a good book which will guide me? Is there a classic text on
this? The coverage of OOP in 'Learning Python' is useful, but I could
do with something more in-depth.

Thanks again,
Andy.




More information about the Python-list mailing list