in reply to how do I do multiple inheritance

I'd like to mention that this is a classic example of how inheritance is taught in OO text books and is also a classic example of how to not use inheritance in the real world.

I wish I could eloquently explain why this is such a bad idea. The basic problem is that inheritance is a very tight binding between types and it can easily tie you up down the road and make things very difficult. You are usually better off having one object contain a reference to another over having the one inherit from the other.

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: how do I do multiple inheritance

Replies are listed 'Best First'.
Re: (tye)Re: how do I do multiple inheritance
by herveus (Prior) on Jan 26, 2002 at 01:53 UTC
    Howdy!

    I'll take a whack at it...

    If you say

    package Employee; use Person; use Gender; @ISA = qw/Person Gender/;
    you are saying that an Employee is both a Person and a Gender.

    You probably want something where Gender is an attribute of Person or Employee. Something like:

    package Person; use Gender; sub new { ... $self->{gender} = Gender->new; ... }

    Now, Persons have among their attributes a Gender. But a Person is not a Gender. HAS-A versus IS-A.

    yours,
    Michael