構造型-Facadeモード
2853 ワード
package facade;
/**
* @author jiq
* :Structural
* : (Facade) , 。
* , 。
*
* OO : --- 。
*
* : , 。
* , ( )。
* , ( )。
* , ( )。
*/
//
class Screen {
String description;
public Screen(String description) {
this.description = description;
}
public void up() { /*...*/ }
public void down() { /*...*/ }
}
//DVD
class DvdPlayer {
String description;
int currentTrack;
Projector projector;
String title;
public DvdPlayer(String description, Projector projector) {
this.description = description;
this.projector = projector;
}
public void on() { /*...*/ }
public void off() { /*...*/ }
public void eject() { /*...*/ }
public void play(String title) { /*...*/ }
public void stop() { /*...*/ }
public void pause() { /*...*/ }
}
//
class Projector {
String description;
DvdPlayer cd;
public Projector(String description) {
this.description = description;
}
public void on() { /*...*/ }
public void off() { /*...*/ }
public void setStereoSound() { /*...*/ }
public void setSurroundSound() { /*...*/ }
public void setVolume(int level) { /*...*/ }
public void setCd(DvdPlayer cd) { /*...*/ }
}
// ( )
class HomeTheaterFacade {
Projector projector;
DvdPlayer cd;
Screen screen;
public HomeTheaterFacade(Projector amp,DvdPlayer cd,Screen screen) {
this.projector = amp;
this.cd = cd;
this.screen = screen;
}
// ( )
public void watchMovie(String movie) {
System.out.println("Get ready to watch a movie...");
screen.down();
projector.on();
projector.setSurroundSound();
projector.setVolume(5);
}
// ( )
public void endMovie() {
System.out.println("Shutting movie theater down...");
screen.up();
projector.off();
}
}
public class FacadeTest {
public static void main(String[] args) {
Projector projector = new Projector("Top-O-Line Amplifier");
DvdPlayer cd = new DvdPlayer("Top-O-Line CD Player",projector);
Screen screen = new Screen("Theater Screen");
HomeTheaterFacade homeTheater = new HomeTheaterFacade(projector,cd,screen);
homeTheater.watchMovie("Raiders of the Lost Ark");
homeTheater.endMovie();
}
}