malaikuangren

What is the purpose or drive to build thing like (xxx),How can it achieve the original goal of design?
工厂模式的演变

Simple Factory

Is a class that can product various sub types of Product. (It is better than the Static Factory. When new types are added the base Product class does not need to be changed only the Simple Factory Class)


 

也许可以将enum为参数应用反射可以使我们不用改变SimpleFactory中的代码。即可以只改变enum中的个数。

 Factory Method

Contains one method to product one type of product related to its type.

包含一个抽象类型的工厂类,并有若干个子工厂类实现该工厂。每个子工厂类分别创建各自的产品类。这也意味着,存在着抽象类型的工厂类关联着一个抽象的产品类。

和Simple Factory不同的是,当增加新的产品时,Factory Method所要产生的修改体现了Open-Close原则。而Simple Factory对于这一变化却无法作到。 


Abstract Factory

Produces A Family of Types that are related. It is noticeably different than a Factory Method as it has more than one method of types it produces. 

和工厂方法不同的是,Abstract Factory中的每个子工厂类创建是若干个不同的子产品类。

 

posted on 2012-04-08 22:11  malaikuangren  阅读(202)  评论(0编辑  收藏  举报