More power than needed ... OOP to Don Clugston
Don Clugston
dac at nospam.com.au
Fri Mar 17 08:57:33 PST 2006
BLS wrote:
> Hi Don,
>
> Don C. wrote :
> <<In OOP, you spend your time trying to find Is-A relationships, but they
> don't exist. Unsurprisingly, hardly anyone is "really" doing OOP. It
> seems to be unimplementable.>>
>
> Oops, what is the matter? . A Is-relation between two classes is just
> inheritance. f.i. cB inherits cA, ergo cB is a special case of cA.
Yes, that's exactly right. I'm saying that inheritance is rarely
appropriate. If you read the Design Patterns GoF book, you'll see that
the #1 rule of OO design is, "Prefer encapsulation to inheritance".
But the defining feature of OO design is inheritance. Without
inheritance, OOP doesn't have polymorphism.
What I find extremely common in practice is "Can-be-treated-as-A"
polymorphic relationships. Most of the time, "is-A" relationships are an
approximation to "Can-be-treated-as-A" relationships. I think that
polymorphism is very important, but inheritance-based polymorphism has
many problems.
More information about the Digitalmars-d
mailing list