The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.

Slides:



Advertisements
Similar presentations
JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access.
Advertisements

Façade Pattern Jeff Schott CS590L Spring What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Façade Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Seven Habits of Effective Pattern Writers Facade Pattern PH pp GoF pp John Klacsmann.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Façade Design Pattern (1) –A structural design pattern.
Design Patterns.
A Behavior Object Pattern
Case Studies on Design Patterns Design Refinements Examples.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
SOFTWARE DESIGN AND ARCHITECTURE
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Structural Design Patterns
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
آرمان حسين‌زاده آذر  Access to data varies depending on the source of the data.  Access to persistent storage, such as to a database, varies greatly.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Java EE Patterns Dan Bugariu.  What is Java EE ?  What is a Pattern ?
JAVA DESIGN PATTERN Structural Patterns - Facade Pattern Presented by: Amit kumar narela Ise Ise
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
The Data Access Object Pattern (Structural – Not a GoF Pattern) ©SoftMoore ConsultingSlide 1.
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
The Singleton Pattern (Creational)
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
The Observer Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Seung Ha.  Façade is generally one side of the exterior of a building, especially the front.  Meaning “frontage” or “face”  In software architecture,
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Abstract Factory Pattern
Façade Pattern:.
Design Patterns Lecture part 2.
Software Design & Documentation
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Presented by Igor Ivković
Design Patterns Satya Puvvada Satya Puvvada.
Jim Fawcett CSE776 – Design Patterns Summer 2003
Object Oriented Design Patterns - Structural Patterns
CMPE 152: Compiler Design January 29 Class Meeting
Presented by Igor Ivković
Presentation transcript:

The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1

Motivation A subsystem is a group of related functions, classes, and interfaces. Structuring a system into subsystems helps reduce complexity, but the interface exposed by the components of a subsystem can be quite complex. A developer who wants to use the subsystem may not know where to begin. A common design goal is to minimize the communication and dependencies between subsystems. One way to achieve this goal is to introduce a façade object that provides a single, simplified interface to the more general facilities of a subsystem. ©SoftMoore ConsultingSlide 2

Motivation (continued) Façade Pattern: Basic Idea Create a Façade class to abstract/encapculate the interface to a subsystem. Clients communicate with subsystem classes through the Façade. The Façade forwards messages to the correct subsystem classes. The Façade may adapt the interface of the subsystem. Clients can always use subsystem classes directly if necessary. ©SoftMoore ConsultingSlide 3

Motivation (continued) ©SoftMoore ConsultingSlide 4 Subsystem without a Façade subsystem classes Client

Motivation (continued) ©SoftMoore ConsultingSlide 5 Subsystem with a Façade subsystem classes Façade Client

Façade Pattern Intent: Provide a unified interface to a set of classes and interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use. Applicability: Use the Façade pattern when –you want to provide a simple interface to a complex subsystem. A façade can provide a simple default view of the subsystem that is good enough for most clients. –there are many dependencies between clients and implementation classes of an abstraction. Introduce a façade to decouple the subsystem from clients and other subsystems, thereby promoting subsystem independence and protability. –you want to layer your subsystems (architectural pattern). Use a façade to define an entry point to each subsystem. Slide 6©SoftMoore Consulting

Façade Pattern (continued) ©SoftMoore ConsultingSlide 7 Structure subsystem classes Façade

Façade Pattern (continued) Participants Façade –knows which subsystem classes are responsible for a request –delegates client requests to appropriate subsystem classes Subsystem classes –implement subsystem functionality –handle work assigned by the Façade object –have no knowledge of the façade; i.e., they keep no references to it. Slide 8©SoftMoore Consulting

Façade Pattern (continued) Collaborations Clients communicate with the subsystem by sending requests to Façade, which forwards them to the appropriate subsystem object(s). Although the subsystem objects perform the actual work, the façade may have to do work of its own to translate its interface to subsystem interfaces. Clients that use the façade don’t usually access the subsystem objects directly. ©SoftMoore ConsultingSlide 9

Façade Pattern (continued) Consequences: The Façade pattern shields clients from subsystem components, thereby reducing the number of objects that clients deal with and making the subsystem easier to use. promotes weak coupling between the subsystem and its clients. –lets you vary the components of the subsystem without affecting its clients –reduces compilation dependencies doesn’t prevent applications from using the subsystem classes if they need to. ©SoftMoore ConsultingSlide 10

Façade Pattern (continued) Implementation Coupling between clients and the subsystem can be reduced even further by making Façade an abstract class with concrete subclasses for different implementations of a subsystem. It can be useful to think of the public and private parts of a subsystem, where the public interface consists of classes that can be accessed by clients. Façade encapsulates “most” of a subsystem’s public interface. Subsystem classes can be grouped together in a Java package, a C++ namespace, or similar grouping mechanisms in other languages. ©SoftMoore ConsultingSlide 11

Façade Pattern Example 1: Compiler A compiler consists of many classes that perform functions such as scanning, parsing, structuring into abstract syntax trees, semantic analysis, optimization, and code generation. Most clients of a compiler don’t care about the details of these classes – they merely want to compile some code. To provide a higher-level interface for its clients, a compiler subsystem can also provide a Compiler class as a façade. ©SoftMoore ConsultingSlide 12

Façade Pattern Example 1: Compiler (continued) public class Compiler {... public void compile(FileReader sourceFileReader, OutputStream targetStream) throws IOException { Source source = new Source(sourceFileReader); Scanner scanner = new Scanner(source); Parser parser = new Parser(scanner); ErrorHandler errorHandler = ErrorHandler.getInstance(); printProgressMsg("Starting compilation..."); ©SoftMoore ConsultingSlide 13 Note Singleton (continued on next slide)

Façade Pattern Example 1: Compiler (continued) // parse source file Program prog = parser.parseProgram(); // check constraints if (!errorHandler.errorsExist()) { printProgressMsg("Checking constraints..."); prog.checkConstraints(); } // optimize if (!errorHandler.errorsExist()) { printProgressMsg("Optimizing..."); prog.optimize(); } ©SoftMoore ConsultingSlide 14 (continued on next slide)

Façade Pattern Example 1: Compiler (continued) // generate code if (!errorHandler.errorsExist()) { printProgressMsg("Generating code..."); prog.setOutputStream(targetStream); prog.emit(); } if (errorHandler.errorsExist()) printProgressMsg("Errors detected " + "-- compilation terminated."); else printProgressMsg("Compilation complete."); } ©SoftMoore ConsultingSlide 15

Façade Pattern Example 2: JavaMail provides a complete API for creating and sending messages including classes that support –message headers– message body –attachments– security A façade can simplify the creation of simple messages and shield most clients from the complexity of the JavaMail API. ©SoftMoore ConsultingSlide 16 Note: A builder pattern could also be used to simplify the creation of simple messages.

Façade Pattern Example 2: (continued) public class Util {... public static void send(String host, String username, String password, String from, String[] to, String subject, String msgText) throws MessagingException {... } public static boolean isValid Addr(String Addr) {... } ©SoftMoore ConsultingSlide 17

Façade Pattern in Java (David Geary) The Java Swing GUI classes provide extensive facilities for windows and dialog boxes, but it is rather tedious and complicated to create a simple dialog box from scratch. Swing provides a façade class JOptionPane that simplifies the creation and use of the most common types of dialog boxes. ©SoftMoore ConsultingSlide 18

Façade Pattern in Java (continued) ©SoftMoore ConsultingSlide 19 JPanel BorderFactory Dialog JDialog BorderLayout JOptionPane Client Window FlowLayout

Java Enterprise Pattern: Session Façade A number of books and articles on Java Enterprise recommend using a session façade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients. Clients access a Session Façade instead of accessing business components directly. ©SoftMoore ConsultingSlide 20

Java Enterprise Pattern: Session Façade (continued) ©SoftMoore ConsultingSlide 21 Client «EJBSession» SessionFacade BusinessObject «EntityEJB» BusinessEntity «SessionEJB» BusinessSession DataAccessObject 1..*

Related Patterns Abstract Factory can be used with Façade to provide an interface for creating subsystem objects in a subsystem- independent way. Mediator is similar to Façade in that it abstracts functionality of existing classes. However, a mediator’s colleagues are aware of and communicate with the mediator instead of communicating with each other directly. In contrast, a façade’s subsystem classes are unaware of the façade. Usually only one Façade object is required. Thus Façade objects are often Singleton. ©SoftMoore ConsultingSlide 22

References Façade pattern (Wikipedia) Façade Design Pattern (SourceMaking) Façade clears complexity by David Geary (JavaWorld) clears-complexity.html Session Façade (Core J2EE Patterns) ©SoftMoore ConsultingSlide 23