more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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:
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 dayBut, TEACH him to fish and you feed him for a lifetime In reply to Re: OO - problem with inheritance
by dmmiller2k
|
|