Java Reference
In-Depth Information
CHALLENGE 17.5
Write down two reasons why Oozinoz might want to provide different
look-and-feels in user environments.
To allow for different look-and-feel standards to exist simultaneously, you can create
an abstract class that returns the standard components. Concrete subclasses can then return
families of components that are appropriate for a specific kind of user environment.
CHALLENGE 17.6
Draw a diagram of an abstract class that will create standard Oozinoz components.
Concrete subclasses of your abstract class will work as factories. Each subclass will produce
components that are appropriate to a specific type of display, such as handheld devices or full
screens. For example, if you create HandheldKit as a subclass of your abstract factory, you
will create HandheldKit.createButton() so that it creates and returns a small button
with a small font size for its label. Each class that implements createButton() will return
an OzButton object with attributes that are consistent with a look-and-feel.
Design Patterns (Gamma et al. 1995) says that the intent for A BSTRACT F ACTORY is that
clients can create families of objects "without specifying their concrete classes." A literal
reading of this might exclude the hierarchy of user interface component factories because
clients will in fact know the exact class for each type of object. However, the point of the
A BSTRACT F ACTORY pattern is that the factory classes isolate clients from knowing how to
create objects.
With the user interface hierarchy, clients know which class to instantiate but do not know how
to initialize each object. For example, clients will rely on the HandheldKit class to know
how to initialize each component to be a reasonable size for a handheld device. Because the
user interface hierarchy of factory classes isolates clients from knowing how to create objects,
this hierarchy follows the intent of A BSTRACT F ACTORY .
Summary
The A BSTRACT F ACTORY pattern lets you arrange for a client to create objects that are part of
a family of related, or dependent, objects. The theme, or common trait of the family, such as
which country the classes pertain to, may run across many classes. In this case, you may
maintain parallel packages, perhaps placing each family in its own package. For GUI
factories, you may not need more than one package if different "classes" of GUI components
differ only in such attributes as text size and cursor type. However you organize your code,
A BSTRACT F ACTORY lets you provide a client with a factory that produces objects that are
related by a common theme.
Search WWH ::




Custom Search