1. 정의
- 서브시스템에 있는 일련의 인터페이스를 통합 인터페이스로 묶는다.
💡 고수준의 인터페이스를 정의하므로 서브시스템을 편리하게 사용할 수 있다.
2. 예시
- 영화를 보기위한 일련의 과정(팝콘, 조명, 스크린, 음량, …)을 하나의 과정으로 통합한다.
3. 그림
4. 클래스 다이어그램
5. 코드
public class Client {
public static void main(String[] args){
TheaterFade theaterFade = new TheaterFade(
new Popcorn(),
new Light(),
new Screen(),
new Amplifier()
);
theaterFade.watchMovie();
}
}
public class TheaterFade {
Popcorn popcorn;
Light light;
Screen screen;
Amplifier amp;
public TheaterFade(Popcorn popcorn, Light light, Screen screen, Amplifier amp) {
this.popcorn = popcorn;
this.light = light;
this.screen = screen;
this.amp = amp;
}
public void watchMovie(){
System.out.println("영화 셋팅 시작");
popcorn.fried();
light.lightControl();
screen.screenControl();
amp.ampControl();
System.out.println("영화 셋팅 끝\\n영화 시작");
}
}
public class Popcorn {
public void fried(){
System.out.println("팝콘 튀기기");
}
}
public class Light {
public void lightControl(){
System.out.println("조명 조절");
}
}
public class Screen {
public void screenControl(){
System.out.println("스크린 조절");
}
}
public class Amplifier {
public void ampControl(){
System.out.println("음량 조절");
}
}
https://github.com/kang-seongbeom/design_pattern
💡 Github에서 디자인 패턴 코드를 볼 수 있습니다.
6. 설명
- 영화를 보기위한 일련의 과정을 TheaterFacade로 통합한다.
- Client는 TheaterFacade의 wathMovie()만 호출하면 모든 일련의 과정이 한 번에 동작한다.
- 이와같이 여러 서브시스템을 통합하여 하나로 묶어 단순화한다.
- 통합된 서브시스템은 pulic인 이상 독립적으로도 접근할 수 있다.
'디자인 패턴' 카테고리의 다른 글
디자인 패턴 - 반복자 패턴(Iterator Pattern) (0) | 2022.11.18 |
---|---|
디자인 패턴 - 템플릿 메소드 패턴(Template Method Pattern) (0) | 2022.11.17 |
디자인 패턴 - 어댑터 패턴(Adapter Pattern) (0) | 2022.11.17 |
디자인 패턴 - 커맨드 패턴(Command Pattern) (0) | 2022.11.17 |
디자인 패턴 - 싱글톤 패턴(Singleton Pattern) (0) | 2022.11.17 |