1 / 21

Facade Pattern

Facade Pattern. Jim Fawcett CSE776 – Design Patterns Summer 2010 Source: Joint presentation by Yu Zhu & Jim Fawcett, Summer 2009. Intent. “ Provide a unified interface to a set of interfaces in a collection of subsystems.

anniebrown
Download Presentation

Facade Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010 Source: Joint presentation by Yu Zhu & Jim Fawcett, Summer 2009

  2. Intent • “Provide a unified interface to a set of interfaces in a collection of subsystems. • Facade defines a higher-level interface that makes the subsystems easier to use.”

  3. Facade Examples • http://www.ecs.syr.edu/faculty/fawcett/handouts/webpages/FawcettHome.htm • Parser (CSE681, CSE687) is façade for rules and actions • PeopleSoft presents façade for many applications: • Registration • Payroll • Yada yada

  4. Motivation • “Common design goal is to minimize the communication and dependencies between subsystems. One way to achieve this goal is to introduce a facade object that provides a single, simplified interface to the more general facilities of a subsystem.” • With façade clients don't have to be concerned with exactly which object in a subsystem they're dealing with. They just call methods on the facade in blissful ignorance.

  5. Motivation

  6. Motivation • Compiler subsystem: • Some language tools might need to access these classes directly. But most clients merely want to compile some code. • Dealing with these low-level interfaces would only complicate their work

  7. Compiler Facade

  8. Communicator Facade

  9. Modeling a legacy application by its basic functions: create, read, update, and delete and exposing these functions as Web methods,Web service facade allows other applications to access legacy data by making use of common Web services through standard protocols Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use Facade for legacy application

  10. Applicability • Use the Facade pattern when: • clients only need a simple default view of the subsystems. Only clients needing more customizability will need to look beyond the facade. • decouple the subsystem from clients and other subsystems • layer subsystems • Facade may not try to hide low-level functionality completely.

  11. Structure

  12. Participants • Facade (Compiler) • knows which subsystem classes are responsible for a request • delegates client requests to appropriate subsystem objects • Subsystem classes (Scanner, Parser…) • implement subsystem functionality • handle work assigned by Facade object • have no knowledge of the facade; that is, they keep no reference to it

  13. Collaborations • Facade forwards the clients’ requests to the appropriate subsystem objects. • Subsystem objects perform the actual work. • Façade may add some functionality of its own. • Facade has to translate its interface to subsystem interfaces. • Clients don’t have to access subsystem objects directly

  14. Consequences • The Facade pattern offers the following benefits: • It shields clients from subsystem components. • It promotes weak coupling between the subsystem and its clients. • help layer a system and the dependencies between objects. • reduce compilation dependencies. • simplify porting systems to other platforms. • It doesn’t prevent applications from using subsystem classes

  15. Implementation • Can further decouple clients and subsystem by making Facade an abstract class with concrete subclasses for different implementations of a subsystem. • Alternative: Configure a Facade object with different subsystem objects.

  16. Implementation • Public versus private subsystem classes. • Public interface to a subsystem consists of classes that all clients can access; private interface is just for subsystem extenders. • Facade class is part of the public interface. It may use private interfaces provided by subsystems (if they grant friendship)

  17. Know Uses • Almost every system you ever designed • Socket communicator shown earlier • SU’s version of People-Soft accessed through mySlice Facade. • ET++: ProgrammingEnvironment for browsing tools • Virtual memory framework: Domain for address spaces

  18. Virtual Memory Framework

  19. Advantages • Facade can make a software library easier to use and understand since the facade has convenient methods for common tasks. • It can reduce dependencies of outside code on the inner workings of a library since most code uses the facade. This allows for more flexibility in developing a system using library. • Facade can wrap a poorly designed collection of APIs with a single well-designed API.

  20. Related Patterns • An adapter wraps an object to change its interface, a decorator wraps an object to add new behaviors and responsibilities, and a facade "wraps" a set of objects to simplify. • Abstract Factory can be used to provide an interface for creating subsystem objects. • Mediator abstracts functionality of existing classes. • Mediator message flow is more complex than Facade. • Facade objects may be Singletons.

  21. Questions • Façade is obvious! Why include in Pattern catalog?

More Related