Wednesday 9 January 2013

Design Patterns- Factory


Factory Design Pattern:


Why?:

Factory Pattern, also known as Factory method pattern, is probably the most commonly used patterns in modern days.
Intent:
Creates objects without exposing the creation logic to the external world
Refers to a newly created object through an interface.

A factory is a Java class that encapsulates the object creation code. A factory creates and return a particular type of a object based on the data type or data provided to the factory method.

How?

The implementation is quite simple, e,g.,

  • If a client want a product, so instead of directly creating it by calling new, it asks for a factory object for a new product by providing information of what it need.
  • The factory instantiates a new concrete product and returns this newly created object to the client.
  • The client uses the object as abstract product without being knowing its concrete implementation.

No comments:

Post a Comment