Newsgroups: comp.lang.smalltalk,comp.object
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uunet!rcm!rmartin
From: rmartin@rcmcon.com (Robert Martin)
Subject: Re: [Q] Multiple Inheritance
References: <JKVG.95Jan29195005@kamet.ccs.neu.edu> <3gr7u7$pgi@ns.oar.net>
Organization: R. C. M. Consulting Inc. 708-918-1004
Date: Fri, 3 Feb 1995 16:23:10 GMT
Message-ID: <1995Feb3.162310.2504@rcmcon.com>
Lines: 69
Xref: glinda.oz.cs.cmu.edu comp.lang.smalltalk:20306 comp.object:26062

drr@terrapin.raleigh.com writes:

>Basically it's the "Duck principle." If it looks like a duck, smells
>like a duck, walks like a duck, and talks like a duck, its probably a
>duck. (or at least a re-usable substitute :-)

In C++:

class Duck
{
  public:
    virutal Image* GetImage() const = 0;
    virtual Odor*  GetOdor() const = 0;
    virtual void   Walk() const = 0;
    virtual void   Talk() const = 0;
};

>Most current OOPS-languages do not directly address this issue. C++
>gives it to you through MI, 

C++ gives it to you through abstract classes, like the one above.  Such
classes can be multiply inherited so that a single object can respond
to more than one interface.

>In fact in most cases MI confuses the issue, because it forces (too
>strong?) you to use the same internal representation for your types
>(according to whatever data structuring rules exist in the target
>language). For example:

>                        Object
>                  +-------+--------+
>                Animal          Machine
>                  |                |
>                 Duck            Robot

>Now say I want to build an RobotDuck (to use during hunting season or
>something :-), I dont want it to have lungs, intestines etc, so I
>really want to structurally derive it from Robot, but I still want it
>to behave like a duck, not a Robot. MI says: "derive from both (but
>you have to fix up the internal consistency)" 

No.  If you have properly separated the interface from the
implementation, then there is no inconsistency to fix up.

class RobotDuck : private Robot, public Duck
{
  ...
};

Here, the class RobotDuck inherits the implementation of Robot and the
interface of Duck.  There are no lungs or brains to get in the way.
The code in RobotDuck will confine itself to appropriate
implementations of the pure virtual functions of the class Duck.  Thus
the RobotDuck will Look like a duck, Smell like a duck, Walk like a
duck and Talk like a duck.  And yet it will have a robot
implementation.

>To summarize, MI gives you lots of oppurtunities to undo done work.

I would rather say that an improper design gives you lots of
opportunities to undo work.  A good designer should always be looking
to separate interface from implementation,  In such designs, MI will
not cause the problems that you have described.

-- 
Robert Martin       | Design Consulting   | Training courses offered:
Object Mentor Assoc.| rmartin@rcmcon.com  |   Object Oriented Analysis
2080 Cranbrook Rd.  | Tel: (708) 918-1004 |   Object Oriented Design
Green Oaks IL 60048 | Fax: (708) 918-1023 |   C++
