Hi,

Recently I faced with following problem in the project which I develop. Let's say I have three classes: A, B and C. A is a base class for B and C and contains common fields:

package A; use strict; use fields qw(id name); sub new { ... }
Classes B and C inherit class A:
package B; use strict; use base qw(A); use fields qw(addr phone city);
and
package C; use strict; use base qw(A); use fields qw(model type);
As I understand when I create an object B it should inherit properties from the base class - id and name. Sure, it works fine till I need to create inside object B object C and and vice versa. But to do that I have to add statement
use C;
into class B and and vice versa. Right after that the problems start. When I create a new object B it doesn't contain thr properties from the base class. The same for object C.

I "solved" it using require instead of use. Another possibility make preloading all custom modules before use it. Any others ideas or suggestions?

Thanks in advance.

Updated: fixed class C definition.

---
Michael Stepanov aka nite_man

It's only my opinion and it doesn't have pretensions of absoluteness!


In reply to Cross reference between two classes and FIELDS by nite_man

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.