Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Design problem while using Builder pattern

Reply
Thread Tools

Design problem while using Builder pattern

 
 
qazmlp
Guest
Posts: n/a
 
      01-31-2004
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?
 
Reply With Quote
 
 
 
 
BarryNL
Guest
Posts: n/a
 
      01-31-2004


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?


 
Reply With Quote
 
 
 
 
iksrazal
Guest
Posts: n/a
 
      01-31-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:26 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
Where's a DOM builder that uses the Builder Pattern to ... buildDOMs? Phlip Python 5 01-13-2010 12:48 PM
May I have a example of design pattern of "composite", I still feel fuzzy after reading book of Addison-Wesley's"design pattern " jones9413@yahoo.com C++ 1 08-31-2007 04:09 AM
Design problem while using Builder pattern qazmlp Java 2 01-31-2004 03:32 PM



Advertisments