Are these both the abstract factory pattern?

北城以北 提交于 2019-12-10 18:49:10

问题


I think the original use of the abstract factory pattern is when you want to create a family of related objects. This is what is described in Gang of Four (GoF) and this tutorial: http://www.oodesign.com/abstract-factory-pattern.html

I keep also seeing posts that the abstract factory pattern can be used for dependency injection, particulary for injecting values that are worked out at runtime. All the uses of abstract factory pattern given here seem to be referring to this method: Why do we need Abstract factory design pattern?

Are these two actually the same pattern, implemented exactly the same, or do they both just have the same name because an abstract factory gets used in them both? Even if they are both implemented in the same way, there are other patterns that have a similar implementation (eg. state and strategy) but different names because they have different motivations, should that be the case here too since the reason for creating the abstract factory in the two cases are completely different?

来源:https://stackoverflow.com/questions/38410899/are-these-both-the-abstract-factory-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!