Sunday, March 21, 2010

Factory

Defines an interface for creating an object, but let the subclasses decide which class to instantiate (defer instantiation to subclasses, without knowing the the specific class being instantiated). This enables to introduce new classes without modifying the code

Benefits:
  • Eliminates the need to bind application classes into your code (Code deals only with interfaces)
  • Enables the subclasses to provide an extended version of an object, because creating object inside a class is more flexible than creating object directly in the client

When to use:
  • A class cannot 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 localise the knowledge of which helper subclass is the delegate.

No comments:

Post a Comment