Card 08/ 08

RecapDifficulty: Advanced1 min

Recap: Abstract Factory Pattern

One factory per family: a new family is cheap, a new kind of product is not.

Abstract Factory gives a program one object that creates every member of a family, so the family is chosen once and cannot be mixed.

  • Intent. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
  • Participants. The abstract factory declares one creation method per kind of product; each concrete factory implements all of them for one family; the client holds the factory and uses only abstract products.
  • Recognise it by shape. One object with several creation methods, where swapping the object swaps every product to a matching set.
  • In the wild. DocumentBuilderFactory.newInstance() finds the platform's XML family, and your code never names a Xerces class.
  • In Python. A family can be a dictionary from kind to class, which keeps the family guarantee with less ceremony.
  • Its cost. Adding a family edits nothing. Adding a kind of product edits the abstract factory and every concrete factory.