Making inheritance less tedious

Michiel nomail at please.com
Tue Feb 27 12:32:39 PST 2007


Bill Baxter wrote:

>> However, I understand your point. If a base class is changed, and you
>> have no source-access to it, you still don't want to entirely break your
>> subclass away from it. Maybe another type of relationship should be
>> formally introduced for such situations. 'Is-kinda-like', or
>> 'is-mutation-of' or something, which would allow suppressing parts of
>> the public interface.
> 
> Isn't that what interfaces and object composition are for?
> If what you have isn't is-A, then like you said inheritance is probably
> not the relationship you're after.  Create a
> ThingsPeopleHaveIrrationalAttatchmentsTo interface and have both Pet and
> Aibo implement it.  Aibo might implement it internally using a Pet member.

Object composition would indicate a 'has-a' relationship. Both normal
inheritance AND interfaces indicate 'is-a' relationships.

I like your solution. But if an 'is-kinda-like' relationship could
formally be created, that would be even better.

If Aibo is-kinda-like Pet (with the food-interface removed), then:

* You could not pass an Aibo to a function that asks for a Pet. You
would simply use Pet for the implementation only.
* Maybe a smart compiler could recognize that the private member 'food'
is not used by any inherited public function and disregard it when
allocating memory.
* Code would become more readable and maintainable.

There could be other advantages.

-- 
Michiel



More information about the Digitalmars-d mailing list