C++ (was RE: Python suitability)
Mitch Chapman
chapman at bioreason.com
Wed Dec 15 17:13:37 EST 1999
Boudewijn Rempt wrote:
>
> Alex Martelli <Alex.Martelli at think3.com> wrote:
> ...
> > Specifically, if you follow the advice of Scott Meyers, in his
> > excellent "Effective C++" (CD Edition): never inherit from a
> > concrete class.
>
> That makes C++ about as powerful as Visual Basic - in essence,
> no inheritance at all, just interfaces... Having just done a
> large project in Visual Basic, I've learnt how painfult that
> limitation can be - and I was kind of surprised when I read
> in Design Patterns that composition should be favoured over
> inheritance. There are no doubt good reasons, but not one
> I can think of.
Composition can help keep the interface of any single class
relatively small.
Composition, in Python, reduces the likelihood of namespace
collisions (e.g. you write over a method or instance variable
defined in a base class, without knowing it).
Guido has recommended composition over inheritance, when
specializing Tkinter widgets. IIRC he used both namespace
collisions and huge namespaces (resulting from subclassing,
resulting *in* huge attribute dictionaries w. poor performance)
as his reasons.
I can't say why, but I've had better luck w. projects when
I design in terms of interacting components than when I design
in terms of interacting sub-/super-classes. But perhaps my
experience would have been different if I'd used a language
in which all instance variables are private, i.e. in which
there's no temptation for a subclass to fiddle w. its base
class member variables?
--
Mitch Chapman
chapman at bioreason.com
More information about the Python-list
mailing list