|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@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]
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.
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |