in reply to Re: Re: inheritance and object creation
in thread inheritance and object creation

Once you decide to use @ISA, you limit choices on how to model things. Your implementation of a Square has to be the same as your implementation of a Parallelogram. Which is an inconvenient implementation of a Square.
Why does the implementation of a square to be the same as one of a parallologram? That's not why how one typically uses inheritance. An implementation of a base class is different than one of a super class - otherwise, there would not be a point in using inheritance. A base class and a super class typically share part of their implementation - and sometimes everything of a super class is inherited by a base class; that is, the base class doesn't redefine any method, or mask any attribute, of the super class.

As for a parallelogram being inconvenient as an implementation of a square, I'm kind of flabbergasted. I cannot think of any property a parallelogram has, that a square hasn't.

Abigail

Replies are listed 'Best First'.
Re: Re: inheritance and object creation
by tilly (Archbishop) on Feb 25, 2004 at 16:05 UTC
    We are obviously talking past each other.

    When I said "implementation of a Square" I meant the data structure that you use. An implementation of a Parallelogram needs more information than an implementation of a Square. Which means that you wind up carrying around extra fields. Furthermore while you can inherit methods for calculating things like the area, it is more efficient to calculate those for a Square directly.

    There is nothing wrong with inheriting an implementation of a Parallelogram. If you have it. But if you really need a Square, it is far simpler and more efficient to implement that directly rather than to deal with the generalization that is a Parallelogram.

    However that point is relatively unimportant (and obviously has nothing to do with multiple inheritance) compared to the others that I had made.