Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Delegation.

I found it interesting that this let me easily move around which helper class or which of a set of collaborating classes actually implemented the thing.

B and C contain references to the A parent, and the 'has' 'handles' construct can specify to delegate all the functions that A is providing.

Likewise, the variable in A that holds its B also delegates functions that B implements.

Methods in either class can just refer to functions in the overall complex, and not care which object is handling it. If you move a function, you change the 'has' lines but no other code!

This is inside what you are calling B:

has tag_formatter => ( is => 'ro', handles => [ qw( format_tag escape filter link_prefixes)], required => 1, weak_ref => 1, # normally points back to parent Creole object ); has config_keeper => ( is => 'ro', handles => [ qw( placeholder_callback link_mapper image_mapper)], required => 1, weak_ref => 1, # normally points back to parent Creole object );
Both of those are pointing back to A. But I could further break up A and make the tag formatter into yet another separate class later!

—John


In reply to Re: Moose design question by John M. Dlugosz
in thread Moose design question by elTriberium

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 taking refuge in the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found