## Abstract Factory pattern

### Introduction

Provides an interface for creating families of related or dependent objects without specifying their specific classes.

### Participants:

#### Abstract factory

- declares an interface for operations that create Abstract product objects.
- this participant cannot be read-only.

#### Abstract product

- declares an interface for a type of Product object.

#### Concrete factory

- implements the operations to create Concrete product objects.
- this participant cannot be read-only.
- this participant cannot be an interface.

#### Concrete product

- defines a product object to be created by the corresponding concrete factory.
- implements the Abstract product interface.
- this participant cannot be read-only.
- this participant cannot be an interface.
- This participant should be entered on a separate page for each Concrete factory. For example, if you specify three Concrete factory classes, and five Abstract products, then there will be three pages where you must specify a set (five, in our case) of Concrete products this Concrete factory object will create (you can select existing classes, or just enter the names of classes you want to be created (they will extend/implement corresponding Abstract product)

The "Copy documentation" option controls whether to copy JavaDoc comments from methods in interfaces participating in the pattern to the stubs of these methods made by the pattern in classes implementing such interfaces.

The "Create pattern links" option controls whether to generate additional links which can be used by this pattern later to determine classes and interfaces participating in the pattern. That means that if you selected this option and used the pattern to create a set of classes and interfaces, the pattern invoked for some participant later (via the popup menu item "Choose Pattern...") will automatically find (if it is possible) all other participants and fill in participant fields with their names.

Also, if you applied the pattern with this option on and invoked the pattern via the popup menu item "Choose Pattern..." for some participant later, the pattern will have additional field called "Use selected class as", containing possible roles for the selected element.

This option is very useful when you are planning to change something in the classes/interfaces participating in the pattern. For example, if this option is on and after creation of the classes and interfaces you added several methods to certain interface-participant (and this change must be reflected somehow in other participants), all you have to do is to select this changed interface, invoke the "Choose Pattern..." dialog for this element and select the original pattern. After that the pattern will determine other participants and you will only have to press "Finish". The pattern will modify all other classes and interfaces accordingly to your changes.

### Applicability

Use Abstract Factory pattern when

- 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 their constraint.
- you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations.