nite_man has asked for the wisdom of the Perl Monks concerning the following question:
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:
Classes B and C inherit class A:package A; use strict; use fields qw(id name); sub new { ... }
andpackage B; use strict; use base qw(A); use fields qw(addr phone city);
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 statementpackage C; use strict; use base qw(A); use fields qw(model type);
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.use 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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cross reference between two classes and FIELDS
by shmem (Chancellor) on Sep 26, 2006 at 10:10 UTC | |
by nite_man (Deacon) on Sep 26, 2006 at 11:03 UTC | |
|
Re: Cross reference between two classes and FIELDS
by sgifford (Prior) on Sep 26, 2006 at 14:50 UTC | |
by nite_man (Deacon) on Sep 26, 2006 at 15:47 UTC | |
by sgifford (Prior) on Sep 27, 2006 at 20:07 UTC |