views:

85

answers:

2

Could someone give me clear samples on when it's best suit to use de AF rather than the FM design pattern?

AF:Abstract Factory FM:Factory Method

Best,

+1  A: 

Abstract factory is when you want control over creation of groups or families of objects that have a one-to-one mapping between them.
e.g. a Window could be a SwingWindow, an AWTWindow or SomeGUIFrameworkWindow. similarly you could have buttons, panes, controls that exist in each family.
You would use the right implementation of the abstractfactory to create the right object. e.g. if you want to swap Swing for AWT, you just swap out the factory object and everything else just works.

http://en.wikipedia.org/wiki/Abstract_factory_pattern (See the example)

Factory method is where you want to control the creation of one type of object.

Gishu
A: 
  • FM: most used when deserializing: create classes based on serial input.
  • AF: most used when an application has to be flexible, so different factories can give different behaviour within the application-framework.

From my answer, it might be clear that I'm more familiar with FM (actually, parametrized factory method, but I have the feeling that this is the most used FM).

stefaanv