Java Reference
In-Depth Information
Chapter 4. Facade
A great advantage of object-oriented (OO) programming is that it helps keep applications
from becoming monolithic programs with hopelessly interwoven pieces. An "application" in
an OO system is a minimal class that knits together the behaviors from reusable toolkits of
other classes. A toolkit or subsystem developer often creates packages of well-designed
classes without providing any applications that tie the classes together. The packages in the
JDK are generally like this; they are toolkits from which you can weave an endless variety of
domain-specific applications.
The reusability of toolkits comes with a problem: The diverse applicability of classes in
an OO subsystem may offer an oppressive variety of options. A developer who wants to use
the toolkit may not know where to begin. This is especially a problem when a developer
wants to apply a normal, no-frills, vanilla usage of the classes in a package. The F ACADE
pattern addresses this need. A facade is a class with a level of functionality that lies between
a toolkit and a complete application, offering a vanilla usage of the classes in a package or
a subsystem. The intent of the F ACADE pattern is to provide an interface that makes
a subsystem easy to use.
Refactoring to Facade
A facade provides an interface, but it does not use a Java interface. Rather, a facade is a class
with methods that make it easy to use the classes in a subsystem.
Consider an example from the early days at Oozinoz, when there were not yet standards for
GUI development. Suppose that you come across an application that a developer has created
to show the flight path of an unexploded shell. Figure 4.1 shows this class. As before,
the underscore in the name of the FlightPanel_1 class is a hint that this class, from
com.oozinoz.applications , needs refactoring.
Search WWH ::




Custom Search