Java Reference
In-Depth Information
SOLUTION 4.3 (from page 48)
The JOptionPane class is one of the few examples of a facade in the Java class libraries. It
is production worthy, configurable, and designed for reuse. Above all else, the
JOptionPane class fulfills the intent of the F ACADE pattern by providing a simple interface
that makes it easy to use the JDialog class. You might argue that a facade simplifies a
"subsystem" and that the solitary JDialog class does not qualify as a subsystem. But it is
exactly the richness of this class's features that makes a facade valuable.
Sun Microsystems bundles many demos in with the JDK. However, these classes are never
part of the Java class libraries. That is, these classes do not appear in packages with a java
prefix. A facade may belong on the Java class libraries, but demos do not.
The JOptionPane has dozens of static methods that effectively make it a utility. Strictly
speaking, though, it does not meet the UML definition that requires a utility to possess solely
static methods.
SOLUTION 4.4
Here are a few reasonable—but opposing—views about the paucity of facades in the Java
class libraries.
As a Java developer, you are well advised to develop a thorough knowledge of the
Java class libraries. Facades necessarily limit the way you might apply any system.
They would be a distraction and a potentially misleading element of the class libraries
in which they might appear.
A facade lies somewhere between the richness of a toolkit and the specificity of a
particular application. To create a facade requires some notion of the types of
applications the facade will support. This predictability is impossible, given the huge
and diverse audience of the Java class libraries.
The scarcity of facades in the Java class libraries is a weakness. Adding more facades
would be a big help.
Search WWH ::




Custom Search