473,761 Members | 3,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
aConcreteBuilde r
=============== =============== =============== =============== =============== ==
- new ConcreteBuilder-------------------------------------------->

- new Director(aConcr eteBuilder)-------->

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

- GetResult()---------------------------------------------------->
There is no problem in calling BuildPartA(), BuildPartB(),
BuildPartC() as a part of Construct(), for all the ConcreteBuilder s.
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 3488


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
aConcreteBuilde r
=============== =============== =============== =============== =============== ==
- new ConcreteBuilder-------------------------------------------->

- new Director(aConcr eteBuilder)-------->

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

- GetResult()---------------------------------------------------->
There is no problem in calling BuildPartA(), BuildPartB(),
BuildPartC() as a part of Construct(), for all the ConcreteBuilder s.
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********@redi ffmail.com (qazmlp) wrote in message
<snip>
There is no problem in calling BuildPartA(), BuildPartB(),
BuildPartC() as a part of Construct(), for all the ConcreteBuilder s.
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
6742
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" value='''+str(variable_name)+'''>''' This works fine, the problem occurs when I want to send a variable to a page
2
4758
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 : ----------- <div id="index" style="position:absolute; width:200px; height:115px; z-index:1; left:-400px; top: 286px visibility:false;">
4
2626
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... http://groups.google.co.uk/group/it.comp.lang.python/browse_thread/thread/44f79c1def2583ca/200adefeefa5f3fa?lnk=st&q=design+pattern+builder+python+-build&rnum=25#200adefeefa5f3fa Unfortunately I can't read the discussion it's possibly in Spanish. Does anyone know of a builder example for python?...
1
1191
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 succesfully, and downloads the newer version from the web server. After completion of download, the component exit the old version application and running the new version. While the new versions main method executing, it calls the dispose method...
0
1467
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 participants: * Context ( SP_XmlPullParser ) o defines the interface of interest to clients o maintains an instance of a ConcreteState subclass that defines the current state.
4
4679
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 button.". But my concern is, if I store the table in SQL Server, then my database would increase its size in no time (program will be used by more than 50 stations.), not to mention the network traffic it would cause, as almost all user activities...
0
844
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 required to transfer few tables from each other for the application to perform a report there upon. while transfering objects b/w the database i got below error: Error at source for row number 2142.Errors encountered so far in this task :1 Page...
2
2902
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. I want to modify the sub string such that it matches only if the
2
2767
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 piece of code: <?php $algorytm = ",,D-,,R,-,,T,-,P,,-F,,,¤,P,,-,I,,-,,,F-,,,E¤,,,G-,,T,-,,S,-O,,,-,,E,¤,,,E,-D,,,,-,P,,,-R,,,,-,,N,,¤,,,S,-,,A,,-,,L,,¤,,,,M-,,,A,-,,,S,-,,F,,-,,,B,¤,,,,G-,,,T,-,E,,,"; $algorytm2 = str_replace(",", "?",...
0
9538
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9353
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9788
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2765
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.