Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Instance data inheritance?by herveus (Prior) |
on May 16, 2005 at 11:25 UTC ( [id://457417]=note: print w/replies, xml ) | Need Help?? |
Howdy!
If you have a case where MyClass::Item ISA MyClass, then you can rebless the object into the subclass. I'm using that technique right now on a project. In my case, I have a set of fairly closely coupled classes (and that coupling is reasonable in this case). The parent class carries the data used all over the place and the subclasses carry more task specific data. As the object (and it could well be a Singleton) gets passed from one phase to another, it gets reblessed into the class that encapsulates the phase specific state and behavior. This may not be the best structure, but it has fallen out rather naturally as I grok this ball of mud I've inherited. In my case, I take care to capture the previous class and (effectively) localize the class change to the phase in question.
yours, Michael
In Section
Seekers of Perl Wisdom
|
|