[Tutor] design questions: pythonic approach to ostriches

Alan Gauld alan.gauld at freenet.co.uk
Sun Apr 24 09:48:01 CEST 2005

> I do remain a bit surprised that there seems to be no way to
> what I naively thought would be the obvious solution -- to remove an
> inherited method from the instance's dictionary.

You can, as Kent said, override the method to do nothing. Some
like Eifell offer better support for that than others.

But there is a danger in removing methods too. By doing so you break
one of the fundamental principles of inheritence:
that everywhere that you use the superclass you can use the sub class.

If you remove the fly() method from your subclass of birds code like
this will break:

birds = [ aSwallow, anOstrich, anEmu, anEagle]

for bird in birds:

Whereas if you simply make fly a null method you can still call it
but nothing happens - a lot safer...

But conceptually the problem (and it is common) is that bird has a
fly() method when not all birds can fly - the object model is broken
at a high level of abstraction.


Alan G.

More information about the Tutor mailing list