I'm trying to figure out the proper way to set up a builder for a collection of heterogeneous items (in data, not type).
Suppose I have a peg board that I want to construct. The pegboard contains a vector of Pegs each with a set of coordinates. The pegs also have a color, and a bunch of other POD properties.
I am implementing the builder pattern to construct different PegBoards but I am unsure of how to treat the following issues:
In some cases I may want to take one or two pegs, and tell the builder to make n copies of them and randomly place them onto the pegboard.
In other cases I may want to explicitly provide a vector of pegs with initialized positions, and properties.
I may want to create a Pegboard with 50% red pegs, 50% blue pegs, or 20% red pegs and 80% blue pegs, etc... My understanding is that with the builder pattern I am stuck making concrete builders for each of the (infinite) possible combinations I want.
Essentially, I like the methodical way the Builder pattern constructs objects, but I need to have some flexibility in the building process as well. Should I have methods in my director such as SetPegColors(vector colors, vector ratios). Who's responsibility is it? Should I keep those methods in my PegBoard and call them if I need to after the building process?
Or is the Builder pattern not the answer to constructing a Pegboard the way I would like?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire