Skip to main content

Factory Method

The Factory Method design pattern defines an interface for creating an object, but let subclasses decide which class to instantiate. This pattern lets a class defer instantiation to subclasses.

Usage     Usage     High

UML class diagram​

A visualization of the classes and objects participating in this pattern.

diagram

Sample code​

This structural code demonstrates the Factory method offering great flexibility in creating different objects. The Abstract class may provide a default object, but each subclass can instantiate an extended version of the object.

Output​

See also​

​