File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Discussing Design Patterns - Factory Method  & Abstract Factory pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "Discussing Design Patterns - Factory Method  & Abstract Factory pattern" Watch "Discussing Design Patterns - Factory Method  & Abstract Factory pattern" New topic
Author

Discussing Design Patterns - Factory Method & Abstract Factory pattern

mini mehta
Ranch Hand

Joined: Oct 22, 2000
Posts: 120
Hi All,
With help of Carl Trusiak and JUNILU LACAR I am starting this first thread regarding design patterns. This thread is one of the thread in the series of threads which I will be starting to discuss about the design and use of the patterns. I would like to start only two threads in a week, so that people get sufficent time to post their arguments.
Like many of us I will be a spectator most of the time because Iam also in course of studying and understanding the design patterns.
As suggested by Junilu, we will be studying the patterns in the order in which it is suggested in http://www.industriallogic.com/papers/learning.html
I think what most people will be looking for will be the following.
1. If possible, what does the particular design pattern does? (But it is assumed that people have atleast read GoF book)
2. Where did u use the particular design pattern.
3. Why did u thought of using the particular design pattern?
4. How did u implemented the particular pattern. If possible, with help of the code.
Lastly I would request the people who have already use the design patterns in their project to come forward and please try to keep this thing going.
---------------------------------------------------------------
This first thread is for Factory Method & Abstract Fatcory Pattern
Junilu Lacar
Ranch Hand

Joined: Feb 26, 2001
Posts: 3008
I would expect participants of this discussion to have at least some idea about Factory pattern. If you do not have the GoF book, use your favorite search engine (I'm partial to Google) and search for "Factory design pattern".
Some opening questions/points of discussion:
From the learning guide: How does Factory Method promote loosely coupled code?
So now that you know what the Factory does, can you think of any real-world examples where it can be applied?
Can you identify any classes in the standard Java library that follow the Factory pattern?
Patterns are not created, they are discovered. Try to look at some your code or designs and see if you can find the Factory pattern in it.
Give some examples of designs that would benefit from being refactored into a Factory pattern.
A pattern that is applied inappropriately can become an AntiPattern. Studying antipatterns can be as beneficial as studying patterns. Can you think of situations where applying the Factory pattern is a bad idea?

[This message has been edited by JUNILU LACAR (edited June 11, 2001).]


Junilu
[How to Ask Questions] [How to Answer Questions] [MiH]
qudsia
Greenhorn

Joined: Jun 05, 2001
Posts: 5
Great idea, this will be useful to a lot of us. I have just started the GoF book and looking forward to the discussion on this thread
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11863
You can certainly see an excellent example of the Factory approach in Sun's JAXP package for XML parsers. JAXP does not actually contain a parser - it provides for creating and configuring a parser according to your requirements.
The factory classes are SAXParserFactory and DocumentBuilderFactory
Bill

Java Resources at www.wbrogden.com
Avijeet Dash
Ranch Hand

Joined: Jan 21, 2001
Posts: 148
I desparetly need to understand How an AbstractFactory is implemented using prototypes.
pl. give me code samples.
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
Can you identify any classes in the standard Java library that follow the Factory pattern?
The Home Interface (EJBHome) is a Factory for the Remote Object (EJBRemote).The Home Object locates the the Remote Object which may be located on the same machine or any machine over the network by using JNDI and creates the instance of Remote Object.
How does Factory Method promote loosely coupled code?
Factory Pattern is based on Indirection.In the above example, the Home Object acts as an indirection and see to it that RemoteObject is not coupled with the JNDI service.
Am sorry for short answers.Can't help it now - am busy with preparation for Test 486. Will come up with detailed description/code by this week-end.
BTW, we can discuss about the Motivation behind Factory Pattern also.Also,the AntiPattern issue which Junilu raised seems very interesting.
Thanks,
Sandeep
[This message has been edited by Desai Sandeep (edited June 12, 2001).]


<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>
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
What fun! A new game .
Let's see. I THINK that this would be an example of an implementation of the Factory pattern.
Once upon a time MicroSoft (yes, I DARE say the name) developed a tool called Access. Then it developed MSWord and Excel. However since each tool was developed by a different group of programmers the user interfaces did not resemble each other much. How irritating to go into Access and find Delete under File, and then go into Excel and have to poke around until you found Delete under Edit (or whatever).
So when it came time to bundle these fine tools up into MSOffice the decision was made to refactor and abstract the applications into a generic MSApplication of which Excel is a subclass. Then a generic MSMenuBar was created with all the standard stuff, and an ExcelMenuBar subclass was created by Excel thus promoting the "common look and feel" across the tools.
Of course they did it in Visual Basic, but I think that the pattern still applies.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
 
subject: Discussing Design Patterns - Factory Method & Abstract Factory pattern
 
Threads others viewed
Good sites for Design patterns
For moderator of this group
Pattern Books
Confused about patterns?
Tutorial on GOF Patterns.
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com