in reply to OO Perl Inheritance - Is it possible somehow?

The short answer to the question posed in the title is undoubtedly yes, it is possible.

However, that being said, composition is, these days, preferred over inheritance - hence inheritance per-se is, altho' extremely useful, not regarded as highly as it once was. To then have an inverse relationship between 2 inheriting classes is a worse idea since the coupling (introduced by the relationship itself) between the classes is exacerbated - leading to all sorts of problems e.g. maintenance, further down the line.

Just my 2 penn'orth

A user level that continues to overstate my experience :-))
  • Comment on Re: OO Perl Inheritance - Is it possible somehow?

Replies are listed 'Best First'.
Re^2: OO Perl Inheritance - Is it possible somehow?
by kEndE (Novice) on Dec 17, 2008 at 17:03 UTC
    I definitely do not see the big picture here.

    If I am not able to reach the child's getSex() sub in a simply way, then whats the point of the inheritance. I mean the Parent should know about the child's subs.

    If I do the inheritance coming from the other direction, so the Son+Daugther are the parents and the Kid is the child then I will be able to reach the subs, but this is logically wrong.

    Kid.pm ------ package Kid; @ISA = (Son); use Son; sub new { } Son.pm ------- package Son; sub new { } sub getSonSex { print("I'm a boy \n"); } test.pl ------- use Kid; use Son; $kid = Kid->new(); # It's OK $kid->getSonSex();
    I'm getting more and more confused about these OO terms :)

      ohhh I am wrong. The child knows about the Parent's subs. :) Because he/she inherits the knowledge of the Elders :)