[Tutor] Re: design questions: pythonic appraoch to ostriches

Alan Gauld alan.gauld at freenet.co.uk
Mon Apr 25 21:48:41 CEST 2005


> (I took a brief detour into Common Lisp after joining
> this list, not too long ago. Thanks Mr. Gauld.)

YOu are welcome, everyone should at least dabble 
in Lisp if only because it teaches you so much about 
the fundamentals of programming.

> method in a subclass. From my limited dealings with
> multiple inheritance, it seems to me the less you have
> to deal with it, the better off you are.

If the language is designed to support it(and I don't 
mean the way C++ does it!) then it can work. But in 
general MI can create its own unique form of torture 
as you play hunt the method...

> >But there is a danger in removing methods too. By
> 
> Where I come from, it wold look in the super class
> for the fly() method when it wasnt found in ostrich,

THats not removing the methjod, thats simply not implementing it.
The OP was suggesting actually removing the method from the 
classes look-up chain. Languages like Eiffel allow you to do this
in a controlled way but that still doen't mean its a good idea!

> What about subclassing bird with FlightlessBird?

YEs thats a valid option if there is a limited set of BIrd types, 
the danger is that the nu,mber of different types of Bird can 
explode exponentially if you aren't careful.

For example take just 3 cases
- BIrds that fly/don't
- Birds that nest/don't
- Birds that migrate/don't

Now you need subclasses for each of those, plus any combination:

Fly + Migrate + Nest
Fly + Don't Migrate + Nest
Fly + Migrate + Don't Nest
Fly + Don't Migrate + Don't Nest.

In fact for N special cases you need 2**N subclasses... Thats a 
lot of classes before you even get near an instance...

> I hope it was ok to post my general thoughts about it
> here...

Of course, thats what a forum is for! :-)

Alan G.



More information about the Tutor mailing list