延續上篇,接著來完成方法 watchMovie()
,執行看電影的動作
public void watchMovie(String movie){
System.out.println("Setting up for a movie");
popper.on();
popper.pop();
lights.on();
lights.dim(20);
screen.down();
projector.on();
projector.wideScreenMode();
amp.on();
amp.setVolume(41);
dvd.on();
dvd.play(movie);
}
}
對使用者來說,他只要切換到「看電影」watchMovie()
模式,不需要理會裡面的運作。
public class HomeTheaterTestMode {
public static void main(String[] args) {
Amplifier amp = new Amplifier();
DvdPlayer dvdPlayer = new DvdPlayer();
Projector projector = new Projector();
Screen screen = new Screen();
TheaterLights lights = new TheaterLights();
PopcornPopper popper = new PopcornPopper();
HomeTheaterFacade myTheater = new HomeTheaterFacade(amp, dvdPlayer,projector, screen, lights, popper);
// 使用者只要負責輸入片名
myTheater.watchMovie("Fast and Furious");
}
}
輸出可以看到所有物件呼叫的方法
___
https://github.com/changtintin/Design-Pattern/tree/7f1a90c143945f3e6634e98fad92885a947664c5/Ch7/Java
Disclaimer
因為讀的是原文版,所以難免會有翻譯詞不達意或是專有名詞上的差異,有錯誤的話歡迎在留言區一起交流!