问题
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