factory method

define interface for creating an object, but let subclass decide which class to instantiate

also know as

virtual constructor

motivation

  • encapsulates knowledge of which subclass to instantiate

applicability

  • when a class can not anticpate the class of the objects it creates
  • to delegate responsibility of object creation

structure

participants

  • Product, ConcreteProduct, Creator, ConcreteCreator

consequences

  • provide hooks for subclasses
  • connects parallel class hierarchies

related

  • Factory, Prototype