Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-26 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found