当使用工厂方法模式呢? [英] When to use Factory method pattern?
本文介绍了当使用工厂方法模式呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用工厂方法模式?
请给我提供一些具体的想法时,使用它的项目呢?
,它是怎么过来的新的关键词更好的办法?
Please provide me some specific idea when to use it in project? and how it is a better way over new keyword?
推荐答案
虽然这并不一定是它的主要用途,这是很好的东西,你有专门的一个类的实例:
Although this isn't necessarily it's primary use, it's good for something where you have specialized instances of a class:
public ITax BuildNewSalesTax()
public ITax BuildNewValueAddedTax()
您需要这两种方法建立一个征税对象,但你不希望有依靠使用新,因为每次的构造可能是复杂的。这样,我封装了所有的变化成很清楚,别人为今后维修单的方法。
You need both methods to build a tax object, but you don't want to have to depend on using "new" everytime because the constructors may be complex. This way I encapsulate all of the changes into a single method that is clear to others for future maintenance.
这篇关于当使用工厂方法模式呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文