|There's more than one way to do things|
Decorator(?) classes and inheritanceby dragonchild (Archbishop)
|on Jan 30, 2004 at 13:29 UTC||Need Help??|
dragonchild has asked for the
wisdom of the Perl Monks concerning the following question:
Update2: For those who still don't get it, here's the gist:
The actual problem is I have a baseclass A and two children B and C, each overriding a different method in A. How do I have D inherit from B and C and have both overriden methods without having D know about the innards of A, B, and C?
I think these are Decorator classes. I've got a hand-rolled OO representation baseclass (similar to Class::MethodMaker, but optimized for our application) that creates mutators given a set of attributes. I've also got two different decorators on that. One is a Singleton baseclass that only overrides new(). The other is a ReadOnly baseclass that overrides make_attr_subs(). The issue I'm having is how to make a readonly singleton, using this system.
If I try to inherit from both classes, I'm only going to get the behavior of the first class in @ISA, because both decorators inherit from the baseclass.
I thought about modifying the child class using import(). I can't see any gaping holes in that theory, but I'm loath to use import() in an OO hierarchy. What do others think?
Update: I don't think it was buzzword bingo, but here's some pseudocode.
Obviously, there's more to the classes than just those methods, including a lot of bookkeeping. But, those are the relevant parts for this discussion. (I also thought that was clear from the text, but maybe not.)
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.