+ All Categories
Home > Documents > Part3- Facad Pattern

Part3- Facad Pattern

Date post: 30-May-2018
Category:
Upload: osamaalqaise
View: 214 times
Download: 0 times
Share this document with a friend

of 15

Transcript
  • 8/14/2019 Part3- Facad Pattern

    1/15

    Facade Pattern

    Facade : Interface .

    The Facade design pattern is a structuralpattern. A structural pattern is "concerned

    with how classes and objects are composed to

    form larger structures.

  • 8/14/2019 Part3- Facad Pattern

    2/15

    Facade Pattern

    Intent

    Provide a unified interface to a set of interfaces in a subsystem. Facade

    defines a higher-level interface that makes the subsystem easier to use.

    Applicability

    You want to layer your subsystem. Use Facade to define an entry point to

    each subsystem level.

    Introduce a Facade to decouple subsystems from clients and other

    subsystems, thereby promoting subsystem independence and portability.

    A Facade can produce a simple default view of the subsystem.

    Collaborations

    Clients communicate with the subsystem by sending requests to Facade,

    which forwards them to the appropriate subsystem object. Clients that

    use facade do not have to access subsystem objects directly.

  • 8/14/2019 Part3- Facad Pattern

    3/15

    Facade Pattern Key Features

    Intent You want to simplify how to use an existing system. Youneed to define your own interface.

    MotivationStructuring a system into subsystems helps reducecomplexity. A common design goal is to minimize

    the communication and dependencies between

    subsystems.

    Problem You need to use only a subset of a complex system. Or

    you need to interact with the system in a particularway.

    Solution The Facade presents a new interface for the client ofthe existing system to use.

  • 8/14/2019 Part3- Facad Pattern

    4/15

    CS 406: Design Patterns 4

    Facade Pattern: Problem

    Client Classes

    Subsystem classes

    Need to communicate

    with

  • 8/14/2019 Part3- Facad Pattern

    5/15

    CS 406: Design Patterns 5

    Facade Pattern: Solution

    Client Classes

    Subsystem classes

    Facade

  • 8/14/2019 Part3- Facad Pattern

    6/15

    CS 406: Design Patterns 6

    Facade Pattern: Why and What?

    Need to provide a simple interface to many, often small,classes. But not necessarily to all classes of the subsystem.

    Facade provides a simple default view good enough for most

    clients.

    Facade decouples a subsystem from its clients.

    Subsystems often get complex as they evolve.

    A facade can be a single entry point to each subsystem level.

    This allows layering.

  • 8/14/2019 Part3- Facad Pattern

    7/15

    CS 406: Design Patterns 7

    Facade Pattern: Participants and

    Communication

    Clients communicate with subsystem classes bysending requests to facade.

    Facade forwards requests to the appropriate

    subsystem classes.

    Clients do not have direct access to subsystemclasses.

    Participants: Facade and subsystem classes

  • 8/14/2019 Part3- Facad Pattern

    8/15

    Facade Design Pattern Structure

    not exposed

    P

    not exposed

    Faade

    exposed

    This call

    replaced

    by 1 & 2;(Client

    cant refer

    to P)

    Client1

    2

    not exposed not exposed

    not exposed

    not exposed

    Adapted from Software Engineering: An Object-Oriented Perspective by Eric J. Braude (Wiley 2001), with permission.

  • 8/14/2019 Part3- Facad Pattern

    9/15

    Structure

  • 8/14/2019 Part3- Facad Pattern

    10/15

    CS 406: Design Patterns 10

    Facade Pattern: Benefits

    Promotes weak coupling between subsystem and its

    clients.

    Helps in layering the system. Helps eliminate circular

    dependencies.

    Shields clients from subsystem classes; reduces

    the number of objects that clients deal with.

  • 8/14/2019 Part3- Facad Pattern

    11/15

    Facade Real World Example

    Consumers encounter a Facade when ordering

    from a catalogue. The consumer calls one number and speaks

    with a customer service representative.

    The customer service representative acts as aFacade, providing an interface to the orderfulfilment department, the billing department,

    and the shipping department.

    Another example : Web-services.

  • 8/14/2019 Part3- Facad Pattern

    12/15

  • 8/14/2019 Part3- Facad Pattern

    13/15

    CS 406: Design Patterns 13

    Example: A compiler

    StackMachineCodegeneratorRISCCodegenerator

    Stream

    BytecodeStream

    CodeGenerator

    Scanner Token

    Parser Symbol

    PnodeBuilder Pnode

    ExpressionNodeStatementNode

    Compiler

    Compile()Invocations

  • 8/14/2019 Part3- Facad Pattern

    14/15

    Related Patterns

    Abstract Factory : The Abstract Factory designpattern can be used with the Facade design pattern tocreate subsystem objects in a subsystem-independentway. It is also possible to replace a Facade with anAbstract Factory to perform the same task.

    Mediator : The Facade and Mediator are very

    closely related except the Mediator abstractsarbitrary communication between colleague objects,while the Facade abstracts functionality of existing

    classes.

  • 8/14/2019 Part3- Facad Pattern

    15/15

    Related Patterns-cont.

    Adapter : both use the indirection patterns ,both hide complexity and reduce coupling but

    adapter hides differences among interfaces to

    similar things while the facade hide identities

    of classes in a subsystem.


Recommended