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:

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; } ...
In your derived class (say, Int), you would have something like the following code:
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 day
But,
TEACH him to fish and you feed him for a lifetime

In reply to Re: OO - problem with inheritance by dmmiller2k
in thread OO - problem with inheritance by uwevoelker

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.