Home Features Programming Design Patterns: Facade Pattern
Design Patterns: Facade Pattern PDF Print E-mail
Written by FemiByte   
Sunday, 01 November 2009 02:38

In this article, we describe the facade pattern in great detail and provide concrete examples on its use.

 

Intent

Provide a unified, simplified interface to a set of more complex interfaces presented by a subsystem.

Motivation

  1. Simplifies the interface for the client; rather than dealing with multiple classes, apis or subsystems it interacts with a single, simplified interface presented by the facade.
  2. Enables loose coupling between the client and the subsytstems it interacts with enabling each to be changed without impacting the other.
  3. Enhances encapsulation, a desirable goal in OOP design.

 

Examples

  1. HouseBuilderFacade - component that presents a simplified interface for building a house.
    It encapsulates functionality to:
    • build the foundation
    • construct floors
    • construct the roof
    • construct the walls
    • install wiring
  2. CarBuilderFacade - build a car.
    Encapsulates functionality to:
    • build the chassis
    • construct the body
    • create and install the steering system
    • install the engine
    • install the electrical system.

Real World Example Usage:

A storekeeper in an auto parts store is an example of the Facade pattern. Buyers go into the store and tell the storekeeper at the front which part they which part they wish to purchase. The storekeeper then goes to the back to retrieve the item.



Consequences of Implementation

 

  1. Simplifies the interface for the client.
  2. Reduces the number of calls to be made to achieve a particular task.
  3. Only a subset of the subsystem's functionality may be made available to the client.

 

Structure

Before Facade Implementation

Before Facade Implementation

After Facade Implementation



Related patterns

The Facade pattern is related to the Adapter pattern in implementation.
However, the difference is in the intent.
For the Adapter pattern the developer is implementing a pre-specified interface,
while the intent of the Facade pattern is to simplify and unify an interface.

Last Updated on Friday, 01 January 2010 22:48
 

joomla 1.5 stats