Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Factor / Factory Method / Factory

 
Avijeet Dash
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it should have been Factory method design pattern
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic