perlquestion
dragonchild
<b>Update2:</b> For those who still don't get it, here's the gist:
<p><i>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>
<p>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.
<p>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.
<p>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?
<p><b>Update:</b> I don't think it was buzzword bingo, but here's some pseudocode.
<code>
package Base;
sub new {
# Creates a new instance of the class
}
sub attrs {
# When called as a class method, will keep track of attribute names
}
sub make_attr_subs {
# Called by attrs() to create the mutators
}
--------------------
package Singleton;
sub new {
# Instead of creating a new instance, will return an already created one.
}
--------------------
package ReadOnly;
sub make_attr_subs {
# Instead of creating just a mutator, will create an accessor X() and a mutator _X().
}
</code>
<p>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.)
<div class="pmsig">
<div class="pmsig-85580">
<p>------
<br><i>We are the carpenters and bricklayers of the Information Age.</i>
<p>Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
</div></div>