Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Re: OO - problem with inheritance

by frag (Hermit)
on Jan 14, 2002 at 21:43 UTC ( [id://138629]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: OO - problem with inheritance
in thread OO - problem with inheritance

So I would like to access the hashref in base_class but the contents should be specific to the calling class.

I'm a little confused about what you're doing. You want each change submitted to the base_class's %parameter_config for confirmation; after that, the actual values get stored in each subclass's own %parameter_config, right? If so, just change your accessors so that before fiddling with %sub_class::parameter_config it first messes with %base_class::parameter_config, to do whatever checking/storing you want done there, and then store the data in each individual subclass's hash. (Or, if you follow your new approach, replace "fiddling with %base_class::parameter_config" with "call validation methods from ValidateNewParameter". Same principle.)

I need the %parameter_config hash before new() is called, because new() needs this information to figure out, if the parameters given to new() are correct. So I need code I can run when the class is loaded.

OK, so put something like this at the start of each subclass:

use vars qw(%parameter_config); # or 'our' but NOT 'my', not if you # use the approach I gave before %parameter_config = &base_class::parameter_config;
And now each subclass has its own copy of %parameter_config. Just make sure that &base_class::parameter_config returns a copy of the hash.

-- Frag.
--
"It's beat time, it's hop time, it's monk time!"

Replies are listed 'Best First'.
Re: Re: Re: Re: OO - problem with inheritance
by uwevoelker (Pilgrim) on Jan 14, 2002 at 21:56 UTC
    Hello Frag,
    thank you for your answer. I agree with you that I could solve my problem by copying the hash in ¶meter_config. But instead I go for ValidateNewParameter.
      by copying the hash

      Note that just copying the hash doesn't work for data structure you have used. Values of hash are hashrefs themselves so new copy will reuse parts of copied data structure. Thus changes in copy of data structure affect original data structure.

      --
      Ilya Martynov (http://martynov.org/)

        Yes, I know. I have to iterate over each hash and make copies. A simple $ref1 = $ref is not enough.
        Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://138629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found