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>
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??
Joined: Apr 02, 2001
Ganesh, Will get back to you as soon as I find something concrete on this. Thanks, Sandeep
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
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%