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

Re: Builder design pattern with lots of parameters - trying to declutter design

by repellent (Priest)
on Mar 29, 2011 at 05:43 UTC ( [id://896091]=note: print w/replies, xml ) Need Help??


in reply to Builder design pattern with lots of parameters - trying to declutter design

    My problem now is that the VehicleDealer and the VehicleBuilder and of course the concrete Product classes (Car and Motorbike) all need to have attributes for all of the parameters I can pass around.

What if you had the notion of a VehicleSpec object that can respond differently to each product class? It will also only allow setting attributes depending on who the caller is (e.g. a Car-type class has no place dictating how long the hand clutch would be). Then each product class will only need a single attribute for the specification it needs.

Just my 2cents. Not sure which direction this will push your code in.
  • Comment on Re: Builder design pattern with lots of parameters - trying to declutter design
  • Download Code

Replies are listed 'Best First'.
Re^2: Builder design pattern with lots of parameters - trying to declutter design
by tospo (Hermit) on Mar 29, 2011 at 08:13 UTC
    That would be sort of simliar to the "Catalog" class I mentioned above in that the parameters taht go into a Vehicle are combined into their own class and can tehn be passed around as instances of it, right?

      Moose has introspection capabilities. Your VehicleDealer can find out what attributes a class has (even before that class is instantiated). If you name your attributes so that they can be identified (i.e. all configuration attributes of class car have a prefix of 'config_') or if simply all attributes of class car are to be configured by VehicleDealer, you don't need any of the attributes in VehicleDealer nor any intermediate classes with attribute lists.

      Even without introspection I would just have a class method in car and motorbike that just returns all the attributes it possesses. So that the information is kept in one place only.

        This may be part of why I decided that sales was not for me:   I was going to be constantly attending product-training classes, for a company that sold a tremendous variety of things.   Even in the present analogy, “cars” and “motorbikes” are not the same thing, except to the extent that both have wheels, they might be colored red, and they can go very fast.   Even though the dealer, in our example, can “introspect” (i.e. “plainly see”) both objects and determine, for example, the number of wheels that each one possesses, that Dealer is still constantly going to be attending new product-training courses.   And in so doing, constantly growing in complexity and declining in maintainability.   It may well be argued that this is where spaghetti comes from.   It truly is a very complex problem, and I do not mean to trivialize it (let alone to suggest that my wild-haired idea has any actual relevance upon it).   But I have encountered the consequences of designs (as we all have...) many times.   “The fact that both of them are, say, ‘vehicles,’ is useful only to a point.”   Our purpose is to build easily-extendable code that will last a dozen years, not to count wheels, and, that’s hard.   While these metaphors do have merit, and are generally worthy based on these merits that they have, they are not the full solution.

        (And so, realizing that I have made no specific conclusion here, I shall now climb down off of this box and put it away.)

        Good point - thanks a lot!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found