473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Design problem while using Builder pattern

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
2 3468


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hansan | last post by:
Hi all. I am working on a webpage where I use python and html. When I want to send one variable to a new script/page I use the following code: 0) print '''<input type=hidden name="eventid"...
2
by: Nasir Wasim | last post by:
How can Access DIV Properties in Script while using Netscape 7.2. I want to use the div id with it's Visibility and left propertyin script but it's not working :-( Main File : ----------- ...
4
by: Jason | last post by:
Hi I really need an example of a builder pattern in python, the closest I could find to something resembling builder was on this thread......
1
by: ITG | last post by:
I am using appupdater component in my application for update a new version of window based application. While using this component with "app doain mode", The old version of application runs...
0
by: stephen.nil | last post by:
http://code.google.com/p/spxml/ spxml is a xml parser, supports PULL-model and DOM-model xml parsing. Using state pattern make it simple to implement the xml parser. State pattern has three...
4
by: diego | last post by:
Hi everyone, What is an effective way of storing user activites while using my program? Like when a user clicks on a button, i would like ro save the following in a log file, "Clicked Edit...
0
by: AdnanZ | last post by:
Hi All, Please if someone can give me an idea of how i can come over the error that has been generated by SQL Server 2000 while using DTS. In my case.i have 2 SQL databases which periodically...
2
by: apoorva.groups | last post by:
Hi I am facing problem while using regexec function. Ex: String = "abc_def_hig" sub string = "def" regexc if I use regexec the it will find the sub string in string and it will return 0....
2
by: firian | last post by:
It's my first post here, so hi all. Anyway, I am trying to work this out, but can't do this alone. I have a specific line of text, I already replaced it with something more user-friendly using this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.