Skip to Content.
Sympa Menu

patterns-discussion - RE: [patterns-discussion] Question - Builder - getResult()

patterns-discussion AT lists.cs.illinois.edu

Subject: General talk about software patterns

List archive

RE: [patterns-discussion] Question - Builder - getResult()


Chronological Thread 
  • From: Jesús Alonso <kenchoweb AT hotmail.com>
  • To: muegge AT iai.uni-bonn.de, patterns-discussion AT cs.uiuc.edu
  • Cc:
  • Subject: RE: [patterns-discussion] Question - Builder - getResult()
  • Date: Wed, 09 Nov 2005 15:43:01 +0100
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/patterns-discussion>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>

Hello Holger,

To be honest, both of the approaches look fine to me. Indeed, I use both of them. I'll try to explain from the cases I'm dealing frequently.

Your approach (delegate the responsibility of choosing the concrete builder and the finished product delivery to the director) is great for any case in which the director can decide which one is the most appropiate for a certain task. That's the approach I take, for instance, when I need to use different parsers for different scene formats when building 3D scenes. So you tell the director to build the scene from a certain filename, it would take the file, obtain its format, and create a certain builder to parse it. Once parsed, the director returns the built scene.

The GoF approach is also good. Indeed, you can see a very similar approach in the SAX XML parser. The Parser (a director) receives a certain handler (concrete builder), and then parses the XML file using it. It's not exactly the Builder pattern as the delivery of the finished product is a feature you have to add in your concrete handler, but the idea is very similar. You define the methods so that when the parser detects a new tag, or a comment, or any other XML element, the handler can continue building the final product.

As you might guess, the GoF approach allows you to avoid the parser have the knowledge of the formats it can read, or the available concrete builders (specially because you define them for your own purpose). The Parser/Director can recognise when it has reached a new tag, or a new attribute, but it's up to the handler to know what information that tag contains and build one element or other depending on that.

I don't know if I'm clear enough. Please, if you have a question or need me to explain this in more depth, please, feel free to ask.

Regards,
Jesús Alonso Abad


Hi,

in the builder pattern typically the client directly fetches the built
product from the concrete builder calling the getResult() method (cf.
the seqence diagram I attached).

I wonder whether it would be better to let the director do this and
return the product in its contruction method. I see two advantages: 1.
the client does not have to know the concrete builder, 2. no
synchronization is needed in case the client and the director work in
parallel. Do I overlook something?

Thanks for advices,

Holger

--
Holger Muegge

University of Bonn, Institute of Computer Science III
Roemerstrasse 164, D-53117 Bonn, Germany
Phone/Fax: +49-228-73-6528 / -4382





<< Builder_sequence.gif >>


_______________________________________________
patterns-discussion mailing list
patterns-discussion AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/patterns-discussion






Archive powered by MHonArc 2.6.16.

Top of Page