Simple Factory

Factory Method

UML Code (PlantUML)

@startuml
Product <|-- ConcreteProduct
Creator <|-- ConcreteCreator
ConcreteCreator ..> ConcreteProduct

class Creator {
  {abstract} fabricmethod()
  oneOperation()
}

class ConcreteCreator {
  fabricmethod()
}
@enduml

  • No new operator is called by calling classes → better to exchange implementation later
  • Better name for virtual constructor
  • Creation of sub classes
  • Add. class which contains class method for creation necessary

Abstract Factory