I think the idea of a catalog/spec object (Vehicle) could be the way to go. The only mandatory parameter for the customer would be Type everything else could by optional i.e. defaults. The default colour could be, say, black. :-) Validate, give it an id, a date and add to a Vehicles object (front end to a db).

Pass the Vehicle->id to whoever needs it. Extra parameters could be added and validated at each stage of the chain and passed on along.

The Vehicles object would allow querying of the db by each part of the chain to establish, say, how many cars, how many bikes. Pass Vehicles an id and get a Vehicle back, perhaps to check the status, e.g. not started, started, completed. The Vehicle_Builder might want to know what new orders have come in today (Vehicles->today). The Car_Builder would want to know if the paint shop has to get a different pot of paint from the store (grrr! customers!!).

Adding a layer of abstraction has reduced all the parmaters to one, the id. It's all been encapsulated in black boxes. Neither Vehicle nor Vehicles know or care about customers, dealers, builders (boo introspection! :-). They know about colours and dates but little else.

While you're at the paper and pencil stage is a good time to nail down the APIs. Hard. I believe the API is key, get it right and the code writes it self. Well chosen object names and methods and the code will "read" well too. And it will be short, a good thing, but be careful not to put the business model (logic) in the objects or you could find yourself in a straight jacket. Get those flow charts right first!

The above is the extent of my experience with OO, so, while no expert I have found this much very helpful. The discussion in that thread is also very useful as it takes up the question of how much you put in an object.

And, of course, there are many other ways to do it :-)

Good luck!


In reply to Re: Builder design pattern with lots of parameters - trying to declutter design by wfsp
in thread 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.