Collection of references and notes on Java and J2EE

Friday, July 06, 2007

Decoupling user and creator in Factory Pattern

It is a good idea to decouple user and creator in factory pattern. This technique is also mentioned as Simple Factory Pattern/Idiom.

Following is diagram from "Manufacturing Java Objects with the Factory Method Design Pattern by Barry Burd and Michael P. Redlich" (http://javaboutique.internet.com/tutorials/factory/) explaining basic factory pattern.


Here, Creator is also user of the Product. This creation and use is tightly coupled.

A "SimpleProductFactory" element can be added to Creator class (composition), which would be responsible of creating Product. Thus, decoupling use and creation of the Product.

Links:-
* Sun Developer Forums: Problem understanding Factory Method Pattern
* Manufacturing Java Objects with the Factory Method Design Pattern by Barry Burd and Michael P. Redlich (http://javaboutique.internet.com/tutorials/factory/)

0 comments: