|
Re: Extends is evil?
Guillermo Schwarz wrote:
>> An example would be to think that a chess club is a set of people, and
>> translating that into defining a class ChessClub that inherits Set.
>
> Why? It has a set of people, why would that be a problem?
The problem is that a ChessClub can only hold people; A Set can hold any
kind of object. So if I say to you, "Give me a Set, any set will do" and
you give me a ChessClub, it might not work. I *think* you gave me a type-of
Set, so I try to add some arbitrary objects to it (eg a bunch of integers
or strings). ChessClub only wants people.
The correct relationship is part-of. People are part-of a ChessClub in the
same way that an engine is part-of a car.
Implementation inheritance is just what it says: sharing code
(implementation) without preserving the kind-of or type-of relationship.
-anthony
|