aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Abstract Factor / Factory Method / Factory 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 "Abstract Factor / Factory Method / Factory" Watch "Abstract Factor / Factory Method / Factory" New topic
Author

Abstract Factor / Factory Method / Factory

Avijeet Dash
Ranch Hand

Joined: Jan 21, 2001
Posts: 148
Guys,
Let me if the one liners below are correct and why Factory as such is not in the 23 GOF Patterns, though its there in the Java Design Pattern book by cooper.
Abstract Factory: helps creating objects for family of simillar objects.
Factory Method: the object creation is deferred to the sub class.
Factory: Object creation by another class.
rgds
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I think it should have been Factory method design pattern


Groovy
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Looks good. There is a nice example of abstract factory in another post from a few days ago. I frankly did not get the distinctions from the GoF book ... it took a few examples to get it.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:
There is a nice example of abstract factory in another post from a few days ago.

Mhh, couldn't find it. Do you have a link, please?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Yknow, I couldn't find it either. A common example is a factory for GUI widgets. Say you had one factory per Look&Feel style. If you bought a new style it would come with a factory. That concrete factory would have to implement an interface or extend an abstract factory. All factory implementations would have getButton, getText, getMenuItem, etc. hope that made sense!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Yes, that made sense.
So, what do you think *is* the difference between Factory Method and Abstract Factory? (We just had this discussion at our Design Patterns Workshop, so I am very interested in everyones opinions...)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I thought this was poorly covered in GoF. Meaning I was too dense to get it the first ten times through.
Factory methods can be useful even with a concrete final factory. I guess a class could have "factory methods" even if its primary function in life was something other than a factory, tho you don't want to blow SRP with too many jobs. Anything that does "get me the right class for this parameter because I don't know ahead of time" is doing a factory method thing.
Abstract factory took me longer. Examples like the UI widgets and others help a lot.
We had a consultant who wrote a FactoryFactory to get a Factory to get an object and there was only one possible class for the object. He must have REALLY loved that chapter in GoF!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract Factor / Factory Method / Factory