The Facade Pattern A Structural pattern - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

The Facade Pattern A Structural pattern

Description:

Structuring a system into subsystems helps reduce complexity ... Oriented Software, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, ... – PowerPoint PPT presentation

Number of Views:296
Avg rating:3.0/5.0
Slides: 20
Provided by: RR41
Category:

less

Transcript and Presenter's Notes

Title: The Facade Pattern A Structural pattern


1
The Facade Pattern - A Structural
pattern
Rajesh Rajasekharan

2
Facade - Agenda
  • Intent (Problem)
  • Facade Pattern Idea
  • Motivation
  • Compiler Example
  • Applicability
  • Participants
  • Collaborations
  • Consequences

3
Facade - Intent
  • To provide a unified interface to a set of
    interfaces in a subsystem
  • It defines a higher-level interface that makes
    the subsystem easier to use

4
The Facade Pattern Idea
Solution
Problem
Facade
5
Facade - Motivation
  • Structuring a system into subsystems helps
    reduce complexity
  • Subsystems are groups of classes, or groups of
    classes and other subsystems
  • The interface exposed by the classes in a
    subsystem or set of subsystems can become quite
    complex
  • One way to reduce this complexity is to introduce
    a facade object that provides a single,
    simplified interface to the more general
    facilities of a subsystem

6
Without Facade
7
With Facade
8
Facade - Compiler Example
StatementNode
ExpressionNode
9
Compiler example (contd.)
  • Consider for example a programming environment
    that gives applications access to its compiler
    subsystem
  • This system contains classes such as a Scanner,
    Parser, programmed , BytecodeStream and
    ProgramNodeBuilder that implement the compiler

10
Compiler example (contd.)
  • Some clients need access to these lower level
    classes but in general most clients do not care
    about the details they only want to compile some
    code
  • To provide a higher level interface that can
    shield clients from these classes the compiler
    subsystem might also include a Compiler class
    which will provide a unified interface to the
    compilers functionality

11
Compiler example (contd.)
  • This Compiler class then acts as a facade when
  • - It offers clients a single simple interface
    to the compiler subsystem
  • - It glues together the classes that implement
    the compilers functionality without hiding them
    completely
  • - The compiler facade makes life easier for
    most programmers without hiding the lower-level
    functionality from the few that need it

12
Facade - Applicability
  • Use the Facade pattern when
  • To provide a simple interface to a complex
    subsystem. This interface is good enough for most
    clients more sophisticated clients can look
    beyond the facade.
  • To decouple the classes of the subsystem from its
    clients and other subsystems, thereby promoting
    subsystem independence and portability

13
Facade - Participants
  • Facade (Compiler)
  • knows which subsystem classes are responsible
    for a request
  • delegates client request to appropriate subsystem
    objects
  • Subsystem classes (Scanner, Parser,etc)
  • implement subsystem functionality
  • handle work assigned by the Facade object
  • have no knowledge of the facade (i.e. keep no
    references to it)

14
Facade - Collaborations
  • Clients communicate with the subsystem by sending
    requests to the Facade objects which forwards the
    request to the appropriate subsystem object or
    objects
  • Facade may do more than delegation
  • Clients do not have access to the subsystem
    objects directly

15
Facade - Consequences
  • It hides the implementation of the subsystem from
    clients, making the subsystem easier to use
  • It promotes weak coupling between the subsystem
    and its clients. This allows you to change the
    classes that comprise the subsystem without
    affecting the clients.
  • It reduces compilation dependencies in large
    software systems

16
Facade - Consequences (contd.)
  • It simplifies porting systems to other platforms,
    because it's less likely that building one
    subsystem requires building all others
  • It does not prevent sophisticated clients form
    accessing the underlying classes
  • Note that Facade does not add any functionality,
    it just simplifies interfaces

17
Some Comparisons
  • Facade vs. Adapter
  • - A facade defines a new interface
  • - An adapter reuses an old interface.
  • Facade Vs. Mediator-Facade does not add any
    functionality, Mediator does
  • - Subsystem components are not aware of Facade
    , Mediator's colleagues are aware of Mediator and
    interact with it

18
Any Questions?
19
Reference
  • Design PatternsElements of Reusable
    Object-Oriented Software, Erich Gamma, Richard
    Helm, Ralph Johnson, and John Vlissides,
    Addison-Wesley, 1995.
Write a Comment
User Comments (0)
About PowerShow.com