2016-06-30 18:14:41 +03:00
..
2016-02-11 12:29:35 +05:30
2014-08-10 10:07:18 +03:00
2016-06-30 18:14:41 +03:00

layout, title, folder, permalink, categories, tags
layout title folder permalink categories tags
pattern Factory Method factory-method /patterns/factory-method/ Creational
Java
Difficulty-Beginner
Gang Of Four

Also known as

Virtual Constructor

Intent

Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

alt text

Applicability

Use the Factory Method pattern when

  • a class can't anticipate the class of objects it must create
  • a class wants its subclasses to specify the objects it creates
  • classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate

Credits