Factory method 和 Abstract factory的区别

Factory method: You have a factory that creates objects that derive from a particular base class

翻译:你有一个继承特定基类的派生类工厂,它能创建不同对象

Abstract factory: You have a factory that creates other factories, and these factories in turn create objects derived from base classes. You do this because you often don't just want to create a single object (as with Factory method) - rather, you want to create a collection of related objects.

翻译:你有一个能创建其它类工厂的类工厂,这些被创建的类工厂反过来是一个继承相同基类的派生类工厂,它能创建不同对象。

你之所以这样做是因为你不只是想创建一个单一的对象(就像工厂方法一样),与factory method 不同的是,你想创建一个相互关联的对象集合!


你可能感兴趣的:(Factory method 和 Abstract factory的区别)