Dear monks,
I'm designing a system that should use the builder pattern (I think...) to build a complex product, all orchestrated by one Director class. The real problem is a bioinformatics one and difficult to explain to non-biologists, but this here is essentially the same in a more "real-world" example.
Let's say we have a class representing a buyer. A buyer requests a new vehicle and the VehicleDealer then gets a VehicleBuilder to build the vehicle, which could be a Car or a Motorbike, so the concrete builder class will be a CarBuilder or a MotorbikeBuilder:

################ ################# # VehicleBuyer # --> # VehicleDealer # ################ ################# | V ################## # VehicleBuilder # ################## | ---------------+----------- V V ############### #################### # CarBuilder # # MotorbikeBuilder # ############### #################### | | V V ######## ############# # Car # # Motorbike # ######## #############
So far so good but my problem now is that a vehicle has lots of parameters, let's say in this case all the customizable details like outside/inside colours and materials etc.

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.
At first I implemented these attributes (I'm using Moose by the way) in each of those classes but that was a lot of duplication, so now I moved them all into Moose roles and consume the roles.
Now I have much shorter code for those classes but I can see problems maintaining this because the attributes that any one of those objects has are spread across several roles and in the end I still have to document each class, so basically I'll end up duplicating, if not the code, then at least the documentation for all those parameters.
My question: how do others deal with a problem like this? Maybe I'm missing a design pattern that would help me out here? Maybe ther just isn't a better way of doing this - just thought I'd ask...
Thanks for your help!!


In reply to Builder design pattern with lots of parameters - trying to declutter design by tospo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.