Java Reference
In-Depth Information
Facade
Pattern Properties
Type: Structural
Level: Component
Purpose
To provide a simplified interface to a group of subsystems or a complex subsystem.
Introduction
Users like to be able to modify a GUI to make it more visually appealing or usable. For example, some users
might have a visual impairment and have trouble reading a small font, so they need to increase the font size.
Forcing the user to step through all the setup screens, (in the current small font size), wading through the modem
and printer and scanner settings until reaching the setup options needed, wouldn't be very user friendly. A wizard,
which would be designed for helping the visually impaired do setup, would be much better.
This kind of help should not limit the options to use and customize the application. Instead, you want to provide a
specialized view of the system, and at the same time keep all the other features. This kind of a Facade pattern is a
front end, or wizard, for the system.
Applicability
Use Facade to:
Make complex systems easier to use by providing a simpler interface without removing the advanced options.
Reduce coupling between clients and subsystems.
Layer subsystems by providing Facades for sets of subsystems.
Description
Most modern software systems are fairly complex. Design patterns help you structure applications and better deal
with the complexity. They often accomplish this by dividing functionality among a series of smaller classes.
Additional classes can also be produced as a result of system partitioning. Dividing a system into several
subsystems helps you deal with complex systems and provides the opportunity to partition the work.
Dividing a system into a number of specialized classes is a good object-oriented design practice. However, having
a large number of classes in a system can be a drawback as well.
Clients using that system have to deal with more objects. Users tend to become confused when presented with
hundreds of configuration options. Car manufacturers, among others, recognize this and adapt their products
accordingly; for instance, when was the last time you had to set the air/gas ratio inside your car engine? Doing
that every time you start your car is not practical. What you want is that you would only have to insert the car key
and turn it to start the car (or actually the car engine). The rest should be handled for you. A client benefits from
having only a few basic options. A Facade can provide these options and can then determine which subsystems to
call.
Normally the Facade will delegate most of the work to the subsystems, but it can do some work itself.
Note that it is not the intent of a Facade to hide the subsystems. The intention is to provide a simpler interface to a
set of subsystems, but clients who need the more elaborate options can still interact with the subsystems.
A setup wizard is one example of a Facade.
Implementation
The Facade object diagram is shown in Figure 3.7 .
 
Search WWH ::




Custom Search