[Tutor] inheritance vs aggregation in Python

Sean 'Shaleh' Perry shalehperry@attbi.com
Tue, 27 Aug 2002 12:10:15 -0700


On Tuesday 27 August 2002 11:45, Erik Price wrote:
> On Tuesday, August 27, 2002, at 01:54  PM, Sean 'Shaleh' Perry wrote:
> > Part of programming is creating something from a specification.
> > Inheritance
> > often makes for a more clear implementation and leads to "self
> > documenting"
> > code.
>
> I see.  So "use it when it makes sense", but you're not -forced- to do
> so as you are in stricter languages.
>

Actually you are not "forced" to in other languages either.  Here in Pyth=
on=20
most new classes will be derived from Object.  This inheritance is simila=
r to=20
the way Java works.

In C++ you have say BaseStream which you derive StringStream from (lets y=
ou=20
read from a string as if it were say stdin) but your C++ implementation o=
f=20
the Python rfc822 module would not derive from either of these it would=20
contain a Stream instance.

Many times large inheritance hierarchies are the sign of poor design.