After reading all of the posts herein, it struck me that you want a separate instance of %parameter_config per derived class, yet shared among all objects of the derived class type.
For clarification, assuming you had three classes derived from the base, e.g., Int, String and Float. There would be exactly three instances of %parameter_config (kept somewhere -- read on), regardless of how many Int, String or Float objects you create.
Each of the %parameter_config things has in common some basic info, plus some class-specific extra stuff added by each subclass.
If this describes your problem, then perhaps I have a solution.
Create a class, say, ParamConfig.pm, which consists basically of a blessed hash (%parameter_config ) containing the basic info required by all types. Add one more hash element: parent_type.
In the constructor (new method) of this class, accept a parameter, parent_type, which is used to initialize the parent_type hash element.
Now, in your base class (from which you will derive Int, String, Float, etc.), you would have code like this:
In your derived class (say, Int), you would have something like the following code:package BaseType; ... BEGIN { my $parameter_config = undef; # accessor - turns the ParamConfig object into a closure sub parameter_config { $parameter_config = $_[0] if @_; return $parameter_config; } } sub new { my $class = shift; # the usual prolog my $type = ref $class || $class; my $self = bless {}, $type; return $self; } ...
package Int; use base qw( BaseType ); use ParamConfig; BEGIN { # create only one of these, at compile time my $pkg_name = __PACKAGE__; my $parameter_config = parameter_config( new ParamConfig( $pkg_name +) ); @{$parameter_config}{ 'int_specific', 'params' } = ( 'vale', 'val2' +); } sub new { my $class = shift; # the usual prolog my $type = ref $class || $class; my $self = bless SUPER->new(), $type; @{$self}{ 'Int', 'Specific', 'Variables' } = (); return $self; } ... # Thereafter, access the class-specific ParamConfig using the accessor +, parameter_config().
This scheme turns instances of ParamConfig into class-level closures (i.e., singletons), share among all members of the derived classes.
Update: the use ParamConfig; belongs in the subclass, not the base class.
dmm
If you GIVE a man a fish you feed him for a dayIn reply to Re: OO - problem with inheritance
by dmmiller2k
in thread OO - problem with inheritance
by uwevoelker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |