In the name of God Fa ç ade Design Pattern Amin Mozhgani Software engineering(II)

Slides:



Advertisements
Similar presentations
Façade Pattern Your Home theatre. Task list In terms of classes.
Advertisements

JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access.
Design Patterns Introduction What is a Design Pattern? Why were they developed? Why should we use them? How important are they?
SE2811 Week 7, Class 2 The Gang of Four and more … Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder.
Design Patterns CS is not simply about programming
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.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
Façade Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Informatics 122 Software Design II Lecture 6 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
Seven Habits of Effective Pattern Writers Facade Pattern PH pp GoF pp John Klacsmann.
Web Application Architecture: multi-tier (2-tier, 3-tier) & mvc
AUDIO MARTIN FILIPELLI Y PAULA CABARCOS A Sound card is an internal computer component that processes audio files. A sound card plays voice as well as.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Façade Design Pattern (1) –A structural design pattern.
Composite Design Pattern. Motivation – Dynamic Structure.
+ Informatics 122 Software Design II Lecture 9 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
Design Patterns Trends and Case Study John Hurst June 2005.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
SOFTWARE DESIGN AND ARCHITECTURE
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
BTS430 Systems Analysis and Design using UML Design Patterns.
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
Design Patterns – II Lecture IV. Singleton Pattern Intent – Ensure a class only has one instance, and provide a global point of access to it Motivation.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
The Façade Pattern SE-2811 Dr. Mark L. Hornick 1.
Testing Extensible Design Patterns in OO Frameworks through Scenario Templates D.S. Sanders Software Verification & Validation.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
Week 9, Class 3: Model-View-Controller Today Happens-Before Adapter and Façade Pattern (high-level) Tuesday: Project code due, 11pm Wednesday: Quiz Choose.
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.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
JAVA DESIGN PATTERN Structural Patterns - Facade Pattern Presented by: Amit kumar narela Ise Ise
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
The PROXY Design Pattern Oleksandra Sopova Feb, 2014.
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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Seung Ha.  Façade is generally one side of the exterior of a building, especially the front.  Meaning “frontage” or “face”  In software architecture,
Façade Design Pattern by Ali Alkhafaji Unified interface for a set of interfaces to promote readability and usability.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
BTS530: Major Project Planning and Design
Object-Orientated Analysis, Design and Programming
Abstract Factory Pattern
Describe ways to assemble objects to implement a new functionality
Façade Pattern:.
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Software Design & Documentation
Design Pattern: Facade
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Abstract Factory Pattern
Decorator Design Pattern
Presented by Igor Ivković
Design Patterns Satya Puvvada Satya Puvvada.
7. Decorator, Façade Patterns
Object Oriented Design Patterns - Structural Patterns
Advanced ProgramMING Practices
10. Façade Pattern SE2811 Software Component Design
Software Design Lecture : 35.
Advanced ProgramMING Practices
Composite Design Pattern By Aravind Reddy Patlola.
Presentation transcript:

In the name of God Fa ç ade Design Pattern Amin Mozhgani Software engineering(II)

Abstract The Facade design pattern provides an easy- to-use interface to an otherwise complicated collection of interfaces or subsystems. It makes things easier by hiding the details of its implementation. It provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.

Introduction The Facade design pattern connects the code we write for applications, which do specific tasks, such as creating a report, and the low level implementation that handle the details, such as reading file, interacting with the network, and creating output. The facade is an interface that an application can use to get things done without worrying about the details. The facade decouples these layers so that they don’t depend on each other, which makes each easier to develop, easier to use, and promotes code re-use.

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

Motivation(II)

Applicability Use the Facade pattern: 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

Consequences Benefits 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 the comprise the subsystem without affecting the clients. It reduces compilation dependencies in large software systems 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 from accessing the underlying classes Note that Facade does not add any functionality, it just simplifies interfaces Liabilities It does not prevent clients from accessing the underlying classes!

An example : Compiler

The Façade Pattern Head First Design Pattern O’Reilly, First Ed. Oct 2004 Eric Freeman & Elisabeth Freeman With Kathy Sierra & Bert Bates

Home Sweet Home Theater

Watching the movie (the hard way) 1. Turn on the popcorn popper 2. Start the popper popping 3. Dim the lights 4. Put the screen down 5. Turn the projector on 6. Set the projector input to DVD 7. Put the projector on a wide-screen mode 8. Turn the sound amplifier on 9. Set the amplifier to DVD input 10. Set the amplifier to surround sound 11. Set the amplifier volume to medium (5) 12. Turn the DVD Player on 13. Start the DVD Player playing And there’s more….When movie is over, you have to do all of this over again, in reverse...Wouldn’t it be as complex to listen to a CD or the.If you decide to upgrade your system, you’re probably going to have to learn a slighty different So what to do ? The complexity of using your home theater is becoming apparent!

The code… popper.on(); popper.pop(); lights.dim(10); screen.down(); projector.on(); projector.setInput(dvd); projector.wideScreenMode(); amp.on(); amp.setDVD(dvd); amp.setSurroundSound(); amp.setVolume(5); dvd.on(); dvd.play(movie);

The Façade is just what you need… With the Façade Pattern, you can take a complex subsystem and make it easier to use by implementing a Façade class that provide one, more reasonable interface.

How the façade operates.. Create a façade for the home theater system.Create a new class HomeTheatreFacade which exposes a few simple methods such as watchMovie().The façade class treats the home theater components as a subsystem, and calls on the subsystem to implement its watchMovie() method.Your client code now calls methods on the home theater façade, not on the subsystem.The façade still leaves the subsystem accessible to be used directly.

Constructing the home theater façade public class HomeTheaterFacade { Amplifier amp; Tuner tuner; DvdPlayer dvd; CdPlayer cd; Projector projector; TheaterLights lights; Screen screen; PopcornPopper popper; public HomeTheaterFacade(Amplifier amp, Tuner tuner, DvdPlayer dvd, CdPlayer cd, Projector projector, Screen screen, TheaterLights lights, PopcornPopper popper) { this.amp = amp; this.tuner = tuner; this.dvd = dvd; this.cd = cd; this.projector = projector; this.screen = screen; this.lights = lights; this.popper = popper; } // other methods here }

HomeTheaterFacade (continue) public void watchMovie(String movie) { System.out.println("Get ready to watch a movie..."); popper.on(); popper.pop(); lights.dim(10); screen.down(); projector.on(); projector.wideScreenMode(); amp.on(); amp.setDvd(dvd); amp.setSurroundSound(); amp.setVolume(5); dvd.on(); dvd.play(movie);}

HomeTheaterFacade (continue) public void endMovie() { System.out.println("Shutting movie theater down..."); popper.off(); lights.on(); screen.up(); projector.off(); amp.off(); dvd.stop(); dvd.eject(); dvd.off();}

HomeTheaterFacade (continue) public void listenToCd(String cdTitle) { System.out.println("Get ready for an audiopile experence..."); lights.on(); amp.on(); amp.setVolume(5); amp.setCd(cd); amp.setStereoSound(); cd.on(); cd.play(cdTitle);}

HomeTheaterFacade (continue) public void endCd() { System.out.println("Shutting down CD..."); amp.off(); amp.setCd(cd); cd.eject(); cd.off();}

HomeTheaterFacade (continue) public void listenToRadio(double frequency) { System.out.println("Tuning in the airwaves..."); tuner.on(); tuner.setFrequency(frequency); amp.on(); amp.setVolume(5); amp.setTuner(tuner);}

HomeTheaterFacade (continue) public void endRadio() { System.out.println("Shutting down the tuner..."); tuner.off(); amp.off();}

Time to watch movie… public class HomeTheaterTestDrive { public static void main(String[] args) { Amplifier amp = new Amplifier("Top-O-Line Amplifier"); Tuner tuner = new Tuner("Top-O-Line AM/FM Tuner", amp); DvdPlayer dvd = new DvdPlayer("Top-O-Line DVD Player", amp); CdPlayer cd = new CdPlayer("Top-O-Line CD Player", amp); Projector projector = new Projector("Top-O-Line Projector", dvd); TheaterLights lights = new TheaterLights("Theater Ceiling Lights"); Screen screen = new Screen("Theater Screen"); PopcornPopper popper = new PopcornPopper("Popcorn Popper"); HomeTheaterFacade homeTheater = new HomeTheaterFacade(amp, tuner, dvd, cd, projector, screen, lights, popper); homeTheater.watchMovie("Raiders of the Lost Ark"); homeTheater.endMovie();}}

References Design Patterns, Erich Gamma, Richard Helm, Ralph Johnson, Jon Vlissides, Addison Wesley, The Facade Design Pattern:brian d foy. The Façade Pattern,Head First Design Pattern:O’Reilly, First Ed. Oct Design Patterns In Java, The Façade Pattern: Bob Tarr.