Java Reference
In-Depth Information
Description
Sometimes an application needs to use a variety of different resources or operating environments. Some common
examples include:
Windowing (an application's GUI)
A file system
Communication with other applications or systems
In this sort of application you want to make the application flexible enough to use a variety of these resources
without having to recode the application each time a new resource is introduced.
An effective way to solve this problem is to define a generic resource creator, the Abstract Factory . The factory
has one or more create methods, which can be called to produce generic resources or abstract products.
Java (“Java technology”) runs on many platforms, each with many different implementations of a file system or
windowing. The solution Java has taken is to abstract the concepts of files and windowing and not show the
concrete implementation. You can develop the application using the generic capabilities of the resources as
though they represented real functionality.
During runtime, ConcreteFactories and ConcreteProducts are created and used by the application. The
concrete classes conform to the contract defined by the AbstractFactory and AbstractProducts , so the
concrete classes can be directly used, without being recoded or recompiled.
Implementation
The Abstract Factory class diagram is shown in Figure 1.1 .
Figure 1.1. Abstract Factory class diagram
You typically use the following to implement the Abstract Factory pattern:
AbstractFactory - An abstract class or interface that defines the create methods for abstract products.
AbstractProduct - An abstract class or interface describing the general behavior of the resource that will be
used by the application.
 
Search WWH ::




Custom Search