# Abstract Factory

- Purpose
- Structure
- Applications
- Consequences

## Purpose

- Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

## Structure

- AbstractFactory : Declares an interface for operations that create abstract product objects.
- ConcreteFactory : Implements the operations to create concrete product objects.
- AbstractProduct : Declares an interface for a type of product object.
- ConcreteProduct: Defines a product object to be created by the corresponding concrete factory.
- Client : Uses only interfaces declared by AbstractFactory and AbstractProduct classes.

## Applications

- a system should be independent of how its products are created, composed, and represented.
- a system should be configured with one of multiple families of products.
- a family of related product objects is designed to be used together, and you need to enforce this constraint.
- you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations.

## Consequences

- It isolates concrete classes. The Abstract Factory pattern helps you control the classes of objects that an application creates. Because a factory encapsulates the responsibility and the process of creating product objects, it isolates clients from implementation classes. Clients manipulate instances through their abstract interfaces. Product class names are isolated in the implementation of the concrete factory; they do not appear in client code.
- It makes exchanging product families easy. The class of a concrete factory appears only once in an application—that is, where it's instantiated. This makes it easy to change the concrete factory an application uses. It can use different product configurations simply by changing the concrete factory. Because an abstract factory creates a complete family of products, the whole product family changes at once.
- It promotes consistency among products. When product objects in a family are designed to work together, it's important that an application use objects from only one family at a time.
  AbstractFactory makes this easy to enforce.
- Supporting new kinds of products is difficult. Extending abstract factories to produce new kinds of Products isn't easy. That's because the AbstractFactory interface fixes the set of products that can be created. Supporting new kinds of products requires extending the factory interface, which involves changing the AbstractFactory class and all of its subclasses.