Abstract Factory – Object Creational

Intent

Provide an iterface for creating families of related or dependent objects without specifying their concreate classes.

Also Known As

Kit

Applicability

Use the Abstract Factory pattern when,

  1. a System should be independent og how its products are created, composed and represented.
  2. a System should be configured with one of multiple families of products
  3. a family of related product objects is designed to be used together and you need to enforce this constaint.
  4. you want to provide a class library of products and you want to reveal just their interface not their implementation.

Structure

Abstract factory structure
Abstract factory structure

 

Participants

  • AbstractFactory (WidgetFactory)
    • Declares an interface for operations that create abstract product objects.
  • ConcreateFactory (MotifWidgetFactory, PMWidgetFactory)
    • Implements the operations to create concrete product objects.
  • AbstractProduct (Window, ScrollBar)
    • Declares an interface for a type of product object
  • ConcreteProduct (MotifWindow, MotifScrollBar)
    • Defines a prouct object to be craeted by corresponding concrete factory.
    • Implemets the AbstractProduct interface
  • Client
    • Uses only interface declared by AbstractFactory and AbstractProduct classes

 

Collaborations

  • Normally a single instance of ConcreteFactory class is created at run-time. This concrete factory creates product objects having a particular implementation. To create different product objects, client should use a different concrete factory.
  • AbstractFactory defers creation of product objects to its ConcreteFactory subclass.

Consequnces

The Abstract Factory pattern has the following benifits and liabilities:

  1. It isolate concrete classes.
  2. It makes exchanging product families easy.
  3. It promotes consistency among products.
  4. Supporting new kinds of product is difficult.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s