Abstract factory pattern

The Abstract Factory (English abstract factory, kit) is a design pattern in the field of software development and belongs to the category of the pattern generation (English creational patterns ). It defines an interface for creating a family of objects, the concrete classes to instantiate the objects are defined in detail. The pattern is one of the design patterns of the so-called Gang of Four ( GoF ) have been published.

Use

The Abstract Factory is used when

  • A system should work regardless of the method of production of its products,
  • A system of one or several families of products is to be configured,
  • To be a group of products produced and shared or
  • If the interfaces are to be provided by products without their implementation in a class library.

A typical application is the creation of a graphical user interface with different themes.

An Abstract Factory combines the responsibilities " Summary of object generation in one place " and " ability to abstract constructors " (see also below under " Related Design Patterns ").

Actors

Benefits

  • The client is of concrete classes isolated.
  • The exchange of product families is possible in a simple manner.

Disadvantages

New types of products can be difficult to add because to be made in all concrete factories changes.

Use in the analysis

Because of the complexity of common two essential responsibilities ( " Summary of object generation in one place " and " ability to abstract constructors " ) this design pattern is practically irrelevant for the analysis.

Example

It aims to develop a collection of games via software. The classes used are

A client (eg, an instance of a player or game master class) can can be created from the abstract factory pawns and a game board. Depending on the specific game is played, for example, provides the ...

  • Chess Factory is a chessboard and chess pieces
  • Lady factory also a chessboard, but wooden tiles
  • Mill factory, a mill board, but also wooden tiles
  • Halma Halma board a factory and hat

Related design patterns

The Abstract Factory is simply a multiple use of the factory method. The Abstract Factory can thus make a whole family of products interchangeably, while the factory method applies only to the product.

Is generally an additional hierarchy of factories into a hierarchy of products can be avoided, the pattern of the prototype can be used. In this pattern to create new objects prototypical instances are copied.

25397
de