2015-08-13 23:54:40 +02:00
---
layout: pattern
title: Factory Method
folder: factory-method
2015-08-15 18:03:05 +02:00
permalink: /patterns/factory-method/
2015-08-20 21:40:07 +02:00
categories: Creational
2015-09-10 15:26:47 +05:30
tags:
- Java
- Difficulty-Beginner
2015-09-22 18:25:56 +05:30
- Gang Of Four
2015-08-13 23:54:40 +02:00
---
2015-11-04 21:13:32 +02:00
**Also known as:** Virtual Constructor
2015-08-13 23:54:40 +02:00
**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.

**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
2015-08-15 18:03:05 +02:00
* classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate
2015-09-22 18:25:56 +05:30
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software ](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 )