Abstract Factor / Factory Method / Factory

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

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

posted Dec 12, 2003 11:01:00

0

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

posted Dec 12, 2003 13:39:00

0

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

posted Dec 13, 2003 19:26:00

0

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!!