aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Factory Method and Builder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Factory Method and Builder" Watch "Factory Method and Builder" New topic
Author

Factory Method and Builder

Ganesh Ram
Ranch Hand

Joined: Jul 20, 2001
Posts: 33
What is the fundamental differance between a Factory method and a builder pattern
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
Could you give me a link/reference for Builder Pattern?Then may be I can compare and let you know the difference between the two.
Thanks,
Sandeep
SCJP2,OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi Sandeep - Go to www.hillside.net/patterns.
There you will find links to UML class diagrams for most of the major design patterns.
Regards, Guy
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Well, that soden't work because of the '.' at the end.
Try:
http://www.hillside.net/patterns/patterns.html
Guy
Ganesh Ram
Ranch Hand

Joined: Jul 20, 2001
Posts: 33
Sandeep,
Take the following scenario.
I am building a Logging component to be used by our system.
I have a class MLog which provides a write and a read method and many other methods too.
I have a Abstract class MLogLine which provides a parse and generate method.
And many extensions of the abstract class viz xLogLine, yLogLine etc.. for each kind of log file.
A user say would create a xLogline and call the write method of MLog.
This creation of the Log line from the object would be partially implemented by xLogline and the other part by mLogLine.
When a user has a line from the log file and would like to parse it, the read of MLog is called.
Internally the read would call a static method from MLogLine that reads the line and instantiates the appropriate xLogLine and returns it back to the user.

Now what pattern is the scenario using. Is it builder??
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Ganesh,
Will get back to you as soon as I find something concrete on this.
Thanks,
Sandeep
Tahir Mansoori
Greenhorn

Joined: Jul 25, 2001
Posts: 29
Hi
I can't understand exactly ur problem problem. I think Design Patterns by Gang of Four is a good refrence for this discussion. But i can help u in difeerence. Difference lies in construcrtion process of both patterns.
Factory Method eliminates the need to bind application specific classess into your code. It supports parallel class hierarchies for frameworks and creates objects in one shot. While Builder Pattern allow you to build differnt kind of objects from differnt parts in step by step construction process.
Suppose we want to develop a window based drawing application system that will be supported on different platforms. For this implementation we have two classess

and

To support this Application to different platfrom one can define a concrete Window class for that platform and concrete DrawingApplication class that implements only createWindow to initialize w1. Abstract method createWindow defers only Window object creation to it subclassess which is platform dependent while doing all the work using w1. This supports parallell class hierarchies with consistent types (interfaces).
In contrast to this Builders decouple building and representation and construct object in step by step process. Suppose we are building generic compiler classess. One way to do this


Compilers with dtfferent Inetrmediate forms can create concrete subclassess for Builder and like TreeBuilder, DagBuilder, TreeArrayBuilder to create Intermediate form.
If we make Parser class an abstract class then differnt Translators for SGML, HTML and other languages can use these Bulders by implementing readNextToken() according to their token representation to produce IntermediateForms. If these IntermediateForms supports same interface then u can also implement Visitor and Iterator Pattern for them to build intermediate two or three address codes and sysntax tree.... More fun
I think This helps
Tahir Mansoori
SCJP2 91%
IBM OOA&D 92%
Ganesh Ram
Ranch Hand

Joined: Jul 20, 2001
Posts: 33
Thanks for the explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Factory Method and Builder