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.

package Base; sub new { # Creates a new instance of the class } sub attrs { # When called as a class method, will keep track of attribute name +s } 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 creat +ed one. } -------------------- package ReadOnly; sub make_attr_subs { # Instead of creating just a mutator, will create an accessor X() +and a mutator _X(). }

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.)

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Decorator(?) classes and inheritance by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.