By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,483 Members | 3,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,483 IT Pros & Developers. It's quick & easy.

Design problem while using Builder pattern

P: n/a
Builder pattern seem to suit my requirements perfectly except in one
case
as described below.
I have used the same example diagram that is used in GOF Design
pattern book, to explain the problem that I am facing.
aClient aDirector
aConcreteBuilder
================================================== ===========================
- new ConcreteBuilder-------------------------------------------->

- new Director(aConcreteBuilder)-------->

- Construct()--------------------------->BuildPartA()------------>
BuildPartB()------------>
BuildPartC()------------>

- GetResult()---------------------------------------------------->
There is no problem in calling BuildPartA(), BuildPartB(),
BuildPartC() as a part of Construct(), for all the ConcreteBuilders.
But, apart from that, one additional function(it is different for each
ConcreteBuilder...different in type and number of arguments) needs to
be called for which aClient has to pass different number&type of
arguments depending on the ConcreteBuilder type.

How do you overcome such a scenario?
Does Builder pattern fit here? Or, do you suggest some other pattern
for this?
Do you find some flaw in the design? And, what are the improvements
that you suggest here?
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


qazmlp wrote:
Builder pattern seem to suit my requirements perfectly except in one
case
as described below.
I have used the same example diagram that is used in GOF Design
pattern book, to explain the problem that I am facing.
aClient aDirector
aConcreteBuilder
================================================== ===========================
- new ConcreteBuilder-------------------------------------------->

- new Director(aConcreteBuilder)-------->

- Construct()--------------------------->BuildPartA()------------>
BuildPartB()------------>
BuildPartC()------------>

- GetResult()---------------------------------------------------->
There is no problem in calling BuildPartA(), BuildPartB(),
BuildPartC() as a part of Construct(), for all the ConcreteBuilders.
But, apart from that, one additional function(it is different for each
ConcreteBuilder...different in type and number of arguments) needs to
be called for which aClient has to pass different number&type of
arguments depending on the ConcreteBuilder type.

How do you overcome such a scenario?
You could always pass a HashMap containing the arguments.
Does Builder pattern fit here? Or, do you suggest some other pattern
for this?
If you need to know which concrete builder you have then Builder
probably doesn't fit. I'd need more concrete details to decide which
pattern is really best - do you have concrete details, or is this just a
homework assignment?
Do you find some flaw in the design? And, what are the improvements
More details... what is actually being built here?
that you suggest here?


Jul 22 '05 #2

P: n/a
qa********@rediffmail.com (qazmlp) wrote in message
<snip>
There is no problem in calling BuildPartA(), BuildPartB(),
BuildPartC() as a part of Construct(), for all the ConcreteBuilders.
But, apart from that, one additional function(it is different for each
ConcreteBuilder...different in type and number of arguments) needs to
be called for which aClient has to pass different number&type of
arguments depending on the ConcreteBuilder type.

How do you overcome such a scenario?
Does Builder pattern fit here? Or, do you suggest some other pattern
for this?
Do you find some flaw in the design? And, what are the improvements
that you suggest here?


Step back a second and try to makes things simpler.

Typically you use the builder pattern when you are gathering the data
for an object gradually before instatiating it. Explain why your
scenerio fits that description. There are also factory method,
abstract factory, memento and protype construction patterns defined in
GOF, as well as delegation. Use what is the closest fit.

As for different types and number of arguments, that's how OO helps
you - do it dynamically and cast. the STL/Java vector type and
countless others are exactly for that - defering type and how many of
them until run-time. Hashmap containsKey() and containsValue() can be
used in the builder constructor, for example.

Hope that helps,
iksrazal
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.