• 工厂模式的演变


    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中的每个子工厂类创建是若干个不同的子产品类。

     

  • 相关阅读:
    POJ2516 构图+k次费用流
    POJ 1511 最短路径之和(spfa或dijkstra+heap)
    windows中配置mongodb
    原型设计
    Erlang的参考资源
    用Erlang实现递归查找文件
    list相关的习题
    springmvc基础知识
    汇编实验4
    实验3 转移指令跳转原理及其简单应用编程
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2438106.html
Copyright © 2020-2023  润新知