Design Patterns -- Abstract Factory

2019-04-15 16:49发布

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.