首页 / 设计模式 / 设计模式之二:工厂方法模式
设计模式之二:工厂方法模式
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了设计模式之二:工厂方法模式,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含18797字,纯文字阅读大概需要27分钟。
内容图文
![设计模式之二:工厂方法模式](/upload/InfoBanner/zyjiaocheng/1113/8a086c5636eb4255a2057d604b61211f.jpg)
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN
style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>22:31:27 2014-01-11
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>个人认为<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘><SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>GOF中对<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Factory Method<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>描述的很清楚,所以会大量引用其内容。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>Factory Method in GOF
-
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Intent
<SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>class defer instantiation to subclasses.
<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>定义了一个用于创建对象的接口,由子类决定实例化哪个类。工厂方法把一个类的实例化延迟到其子类。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘margin: 0px; padding: 0px; color: rgb(51, 51, 51); line-height: 19px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);‘>工厂方法模式较简单工厂模式,修改时关闭的,扩展时开放的,完全符合开放<SPAN lang="EN-US" style=‘margin: 0px; padding: 0px; color: rgb(51, 51, 51); line-height: 19px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);‘>-<SPAN style=‘margin: 0px; padding: 0px; color: rgb(51, 51, 51); line-height: 19px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);‘>封闭原则。
-
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Also Known As
<SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Virtual Constructor
<SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>虚构造器
-
<SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Motivation
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Two key abstractions in this <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>framework are the classes <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Application<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘> and <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Document<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>.
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Because the particular Document subclass to instantiate is application-specific, the Application class can‘t predict <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>the subclass of Document to instantiate—the Application class only knows whena new document should be created, <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>not what kindof Document to create. This creates a dilemma: The framework must instantiate classes, but it only <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>knows about abstract classes, which it cannot instantiate.
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>The Factory Method pattern offers a solution. It encapsulates the knowledge of which Document subclass to create <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>and moves this knowledge out of the framework.
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>因为被实例化的特定<EM style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>Document子类是与特定应用相关的,所以<EM style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>Application类不可能预测<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>到哪个<EM style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>Document子类将被实例化———<EM style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>Application类仅知道一个新的文档何时应被创建,而不<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>知道哪一种<EM style=‘font-family: 微软雅黑, "microsoft yahei";‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Document将被创建。这就产生了一个尴尬的局面:框架必须实例化类,但是它只<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>知道不能被实例化的抽象类。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Factory Method 模式提供了一个解决办案。它封装了哪一个<SPAN style=‘line-height: 1.5; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Document<SPAN style=‘line-height: 1.5; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>.<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>子类将被创建的信<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>息并将这些信息从该框架中分离出来,如下页上图所示(<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>防GOF<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>)。Application和Document 也可为关联。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Application subclasses redefine an abstract <SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>CreateDocument<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘> operation on Application to return the appropriate <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Document subclass. Once an Application subclass is instantiated, it can then instantiate application-specific <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Documents without knowing their class. We <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>call CreateDocument a factory method<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘> because it‘s responsible for <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>"manufacturing" an object.
<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Application <SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>的子类重定义 <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Application <SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>的抽象操作 <SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>CreateDocument <SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>以返回适当的 <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Document <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>子类对象。一旦一个 <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>Application<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>子类实例化以后,它就可以实例化与应用相关的文档,而无<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>需知道这些文档的类。我们称 <SPAN style=‘font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px; text-decoration: underline;‘>CreateDocument <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>是一个工厂方法( factory method) ,因为它负<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>责“生产”一个对象。
-
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Applicability
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Use the Factory Method pattern when
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>● a class can‘t anticipate the class of objects it must create.
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>● a class wants its subclasses to specify the objects it creates.
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>● classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of <SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>which helper subclass is the delegate.
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>在下列情况下可以使用 Factory Method模式:
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>● 当一个类不知道它所必须创建的对象的类的时候。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>● 当一个类希望由它的子类来指定它所创建的对象的时候。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>● 当类将创建对象的职责委托给多个帮助子类中的某一个,并且你希望将哪一个帮助子类<SPAN style=‘line-height: 1.5; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>是代理者这一信息局部化的时候。
-
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Structure
-
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>代码
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>代码就不贴了,不是不能也不是不愿而是不必。网上误导的已经够多了,我解释下"而是不必",你们就会心领神会了。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>假定有CA/<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CA* <SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>和 CB<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘><SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>/<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CB*。CA要使用CB。
<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>● <SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>简单工厂模式
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>//根据条件创建CB
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>CA.CreatB = new <SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>CB_N();
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>//CA使用CB
<SPAN style=‘text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>CB* pcb= CA.CreatB<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>;
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>CA知悉<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CB*,自己创建CB并使用CB。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>就此关联性举个例子。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>假如你有一个亲身亲为的领导,自己要吃饭了。不是差遣你点外卖,而是自己点。
<SPAN style=‘line-height: 26.66px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>● <SPAN style=‘line-height: 26.66px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>工厂方法模式
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>//根据条件创建CB
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CA_N.CreatB = new <SPAN style=‘line-height: 26.66px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>CB_N();
<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CA_N<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>.CreatB即为Factory Method。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>//CA使用CB
<SPAN style=‘text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CB* pcb=<SPAN style=‘text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘> CA.CreatB<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>; //<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>CA.CreatB <SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>由 <SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CA_N<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>.CreatB实现
CA不用知悉<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>Concrete<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>CB*,只管使用CB。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>这个就好比你遇上一个甩手领导了,自己要吃饭了,就差遣你点外卖。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>● <SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 16px;‘>总结
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>通过以上比较可知,两者最关键的区别就是创建时机不同。这就是<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>"而是不必"<SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>的原因了。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘><SPAN style=‘line-height: 26.66px; text-indent: 28px; font-family: 微软雅黑, "microsoft yahei"; font-size: 15.55px;‘>
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>所以网上用代码来阐述的例子,总是让人感觉在抽象、纯虚里绕来绕去。设计模式是为应用场景服务的,精确定位应用场景才能正确应用。
<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>软件是人的思想衍生,<SPAN style=‘font-family: 微软雅黑, "Microsoft YaHei"; font-size: 16px;‘>也是模拟人的解决思维。我们应该人性地看待软件,主导软件,把人的灵魂注入软件,而不是从软件中汲取精神。
原文:http://www.cnblogs.com/freezlz/p/3518167.html
内容总结
以上是互联网集市为您收集整理的设计模式之二:工厂方法模式全部内容,希望文章能够帮你解决设计模式之二:工厂方法模式所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。