Design Patterns -- Abstract Factory

来源:互联网 发布:mac 命令 alias 编辑:程序博客网 时间:2024/05/16 18:03

The intent of Abstract Factory is to provide for the creation of a family of related, or dependent, objects. see pic:

Additional note is below:( reference from http://www.dofactory.com) : 

  • AbstractFactory  (ContinentFactory)
    • declares an interface for operations that create abstract products
  • ConcreteFactory   (AfricaFactory, AmericaFactory)
    • implements the operations to create concrete product objects
  • AbstractProduct   (Herbivore, Carnivore)
    • declares an interface for a type of product object
  • Product  (Wildebeest, Lion, Bison, Wolf)
    • defines a product object to be created by the corresponding concrete factory
    • implements the AbstractProduct interface
  • Client  (AnimalWorld)
    • uses interfaces declared by AbstractFactory and AbstractProduct classes

 using the term: 产品族(Product Family),the former pic is like:

 

 

In this pattern, speaking loosely, a package is usually a "family" of classes, and an abstract factory produces a "family" of objects.