Here the question is "How the child (object) know its parent(object)" and NOT "Parent knowing the child"

In general, the answer (regardless of language) is "there is no general answer". OO is about the relationships of classes to each other, specifically "is-a" relationships in the case of inheritance. If the objects are also related (which they may or may not be), you have to set up some form of references from one to the other to create that relationship as it's not an inherent part of OO.

The example in the other thread confuses the issue because it defines a parent class (person) which is intended to represent a mother and a child class (child) which is intended to represent her son. The differences between the OO parent/child relationship ("a child is a person") and the real-world parent/child relationship ("Billy is Alice's son") make it difficult to discuss clearly.

If we take a different set of classes, say Vehicle and Truck, then it is more obvious that "a Truck is a Vehicle" without the implications that any individual truck (instance) has a parent (instance). (And, if it did, its "parent" would be either a Factory or a Person::AutoDesigner, not a Vehicle.)

Can you help us to solve this problem, other than creating instance of base classes inside our package?

I still don't see what the problem is. As I asked in the other thread, "what is it that you want to accomplish without creating instances of base classes inside your package?" If you're creating instances of the base class, then that suggests to me that you're thinking of the base class and derived class as two different things (Billy and Alice, in the original example) and, if that's the case, then they should be instantiated as two separate objects rather than trying to trick one object into doing double duty.


In reply to Re: SUPER in OOPerl is dumped with $self by dsheroh
in thread SUPER in OOPerl is dumped with $self by atemon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.