Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Class or Object composition ??

by exussum0 (Vicar)
on Oct 03, 2006 at 21:53 UTC ( [id://576198]=note: print w/replies, xml ) Need Help??


in reply to Class or Object composition ??

From experience, any code that interacts with the outsdie world needs to be seperated out, as seperate objects. I'd suggest the decorator pattern.

For instance, if you were implementing a calculator, your object would have methods such as add(...), subtract(...), divide(...). Each of these methods would call a decorator class you fed in at some point. What if you wanted to work w/ them as BigInteger, or IEEE Floating point, or some other method for floating point?

The only difference from what I'm stating and your second example, is you wouldn't "use SendRcv;" w/i there. You'd do something like...

$server = Server->new( SendRcv->new() )
Or in two lines..
$server = Server->new(); $server->set_comm_i_cant_think_of_better_name( SendRcv->new() )
</code>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-20 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found