Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: Often Overlooked OO Programming Guidelines

by polymorpheus (Novice)
on Sep 06, 2012 at 16:40 UTC ( #992140=note: print w/ replies, xml ) Need Help??

in reply to Re: Re: Often Overlooked OO Programming Guidelines
in thread Often Overlooked OO Programming Guidelines

I am with you on the use of delegation. However, you could take your example one step further and use dependency injection to fully decouple the two classes.

package Bar; sub new { my ($class, %args) = @_; bless \%args, $class; } sub wonk { my $self = shift; $self->{_foo}->wonk(@_); # delegation! } package main; use Bar; use Foo; my $bar = Bar->new(_foo => Foo->new());
Now Bar is fully independent of Foo (coupled only by the implied "interface" which consists of the wonk() method). This also makes testing easier.

Comment on Re^3: Often Overlooked OO Programming Guidelines
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2016-02-13 11:22 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (427 votes), past polls