Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations

Presentation on theme: "Façade Pattern Your Home theatre. Task list In terms of classes."— Presentation transcript:

1 Façade Pattern Your Home theatre

2 Task list


4 In terms of classes

5 But there’s more??

6 Lets façade it

7 Façade steps 1.Create a new class HomeTeathreFacade, which exposes simple methods like WatchMovie(). 2.The façade class treats home theatre component as sub system, and calls on the sub system to implement its WatchMovie() method. 3. Your client code now calls methods on the home theatre Façade, not on the subsystem. So now to watch a movie we just call one method, watchMovie(), and it communicates with the lights, DVD player, projector, amp, screen and popcorn maker for us 4.The Façade still leaves the subsystem accessible to be used directly. If you need the advanced functionality of the subsystem classes, they are available for use.

8 Home Theater Facade 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) {

9 this.amp = amp; this.tuner = tuner; this.dvd = dvd; = cd; this.projector = projector; this.screen = screen; this.lights = lights; this.popper = popper; } 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();; }

10 public class CdPlayer { String description; int currentTrack; Amplifier amplifier; String title; public CdPlayer(String description, Amplifier amplifier) { this.description = description; this.amplifier = amplifier; } public void on() { System.out.println(description + " on"); } public void off() { System.out.println(description + " off"); } public void eject() { title = null; System.out.println(description + " eject"); } public void play(String title) { this.title = title; currentTrack = 0; System.out.println(description + " playing \"" + title + "\""); }

11 Starting the 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(); }

12 definition Façade pattern provides a unified interface to a set of interfaces in a subsystem. Façade defines a higher level interface that makes the sub system easier to use.

13 Who does what? PatternIntent DecoratorConvert one interface to another Adapter Don’t alter interface, but add responsibility FaçadeMake Interface simpler

Download ppt "Façade Pattern Your Home theatre. Task list In terms of classes."

Similar presentations

Ads by Google