com.dp4j
Annotation Type AbstractFactory


@Documented
@Target(value=TYPE)
public @interface AbstractFactory

Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes. [GoF, p87] Abstract Factory UML Class Diagram

Motivation

If an application is to be portable, it needs to encapsulate platform dependencies. These "platforms" might include: windowing system, operating system, database, etc.
An Abstract Factory is implemented by a concrete factory for each platform. Each factory has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them. The binding to a concrete factory occurs at run-time.

Usage & Examples

Used when:
  • the system should be configurable to work with multiple families of products.
  • a family of products is designed to work only all together.
  • the system needs to be independent from the way the products it works with are created.
  • Look & Feel Example

    Building a GUI that works on top of different platforms Look&Feels, like MS-Windows and Motif, is the most common example for using an Abstract Factory. The client interacts with a LookAndFeel Abstract Factory which defines the methods to create the desired Widgets (buttons, Menus, etc.), and the interfaces of those widgets. Then for each Look&Feel supported, a concrete subclass implements LookAndFeel factory methods, returning the concrete widget for each platform. Finally, at run-time (through a preference option, for example) the client is bound to the desired concrete LookAndFeel factory.

    See Also:
    GUIFactory Example Code, Abstract Factory



    Copyright © 2011. All Rights Reserved.