Facade
From CSSEMediaWiki
Revision as of 07:47, 24 July 2009 by JaninaVoigt (Talk | contribs)
The facade pattern is used to provide a simple interface to a complex set of interfaces. Often facades are produced to further simplify common APIs or adapt them to a more specific use.
Contents |
Structure
TODO: add UML diagram
Participants
- Facade: The Facade knows the internal workings of the subsystem and which classes have which responsibilities. It delegates client request to the correct part of the subsystem.
- Subsystem classes: These classes implement the functionality of the subsystem and handle work assigned to them by the facade. However, they are unaware of the existence of the facade.
Collaborations
- Clients communicate with the subsystem through the facade and don't have access to the subsystem objects directly.
Use When
- You want to provide a simple interface to a complex subsystem.
- Clients are closely coupled with the implementation of an abstraction. Use Facade to decouple clients from the implementation.
- You want to layer subsystems. Create a Facade for each subsystem level as an access point and get the subsystems to communicate with each other through their facades.
The design pattern
- provides convenient methods
- makes the inner system more flexible since less methods are called from the outside
- can turn a badly designed API into a very well usable one
Example
The boot process of a computer can be modeled as a Facade. The system's boot() method is called. This method now starts and configures all the services and programs needed to use the computer.
Design patterns | |
---|---|
Creational: Abstract Factory | Builder | Factory Method | Prototype | Singleton |