Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Moose design question

by moritz (Cardinal)
on May 19, 2011 at 19:22 UTC ( [id://905787]=note: print w/replies, xml ) Need Help??


in reply to Moose design question

I have a module A which has multiple features B, C, D, because multiple people will work on these and it would be nice to have this logical separation of the different features.

That's not the way you should design object-oriented code.

You should find useful abstractions based on how they interact with each other, not by who develops them.

It's not making use of any OO concepts

That might be an indicator that you don't actually need any OO - how about just a hash with objects B, C, D? Or a sub that returns those objects, based on the argument you pass to it?

The existence of shiny OO tools don't mean you have to use them for every case.

What doesn't your current solution do that you might want from it? Extensibility? You can still stick other objects in the attributes if you make them writable (a hash provides that by default).

sub another_method { my ($self) = @_; $self->a->exec(...); # Stuff related to C }

Looks like delegation would make your life easier here.

But in general it is very hard to give advise based on such general descriptions. It could be anything from "Don't use OO at all" to "use delegation" or "use roles" or "stick with your current approach" - we just don't have enough context to decide.

Replies are listed 'Best First'.
Re^2: Moose design question
by elTriberium (Friar) on May 19, 2011 at 20:18 UTC
    Thanks for you answer.
    You should find useful abstractions based on how they interact with each other, not by who develops them.
    I agree, this was not a good example. But as I mentioned these modules are logically separated, so I wanted to introduce the abstraction in the class design.
    Looks like delegation would make your life easier here.
    Thanks for that tip and also to John M. Dlugosz for mentioning delegation, too. I have not looked into this before, will definitely do that now.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-03-28 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found