Factory Method

Intent

Define an interface for creating an object, but let subclasses decide which class to instantiate.

product

Solution

Consequences

Variation

Make the FactoryMethod in the Creator class construct a default object that may be overridden by subclasses.

Consequences

Variation

Pass a parameter to the FactoryMethod to identify the kind of product to create.

Consequences

Factory methods may create multiple kinds of objects in a single function; however, this will make the FactoryMethod code more complex and may make it more difficult to extend the Creator class to support new product object types.

Related Patterns


Quick Pick