Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Moose design question

by John M. Dlugosz (Monsignor)
on May 19, 2011 at 19:22 UTC ( [id://905786]=note: print w/replies, xml ) Need Help??


in reply to Moose design question

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://905786]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found