CSC/ECE 517 Fall 2009/wiki3 16 AD: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 10: Line 10:
== Comparison with other Creational Patterns ==
== Comparison with other Creational Patterns ==


=== Comparison with Singleton Pattern ===


Singleton pattern is a creational pattern which is used in situations where just only one object of the class has to be created.


=== Comparison with Builder Pattern ===
=== Comparison with Builder Pattern ===

Revision as of 04:11, 18 November 2009

Definition

Factory Method is a creational pattern. This pattern helps to model an interface for creating an object which at creation time can let its subclasses decide which class to instantiate.It is called as Factory Pattern as it is responsible for "Manufacturing" an Object. It helps instantiate the appropriate Subclass by creating the right Object from a group of related classes. The Factory Pattern encourages loose coupling by eliminating the need to bind application-specific classes into the code.

Overview

This topic deals with the Factory method design pattern.It explains Factory design pattern and compares with other creational pattern to highlight the uniqueness and distinguishing features of the pattern.It also gives examples of where factory design pattern is used and scenarios wherein its more suitable than other creational patterns.

Comparison with other Creational Patterns

Comparison with Builder Pattern

In Factory pattern, the factory is in charge of creating various subtypes of an object depending on the needs.

Where as in Builder pattern, the composition of the objects might differ within the same subclass.

An example of a Factory method CarCreate might return a Audi or a Toyota where as in the same scenario if we are using a Builder pattern, it allows us to create objects with finer granularity like specifying different engine specifications (a 4 cylinder engine or a 6 cylinder engine)for the objects. As seen from the above example the Factory pattern is a simpler version of the Builder Pattern.

UML diagram of Builder Pattern

Source: [1]

Comparison with Prototype Pattern

Comparison with Abstract Factory Pattern

In depth Analysis

External Links and References