[λ””μžμΈ νŒ¨ν„΄] νŒŒμ‚¬λ“œ νŒ¨ν„΄ (Facade Pattern)

λ°˜μ‘ν˜•
πŸ’‘ νŒŒμ‚¬λ“œ νŒ¨ν„΄ (Facade Patter)
μ–΄λ–€ μ„œλΈŒμ‹œμŠ€ν…œμ˜ 일련의 μΈν„°νŽ˜μ΄μŠ€μ— λŒ€ν•œ ν†΅ν•©λœ μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ œκ³΅ν•œλ‹€. νΌμ‚¬λ“œμ—μ„œ κ³ μˆ˜μ€€ μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ •μ˜ν•˜κΈ° λ•Œλ¬Έμ— μ„œλΈŒμ‹œμŠ€ν…œμ„ 더 μ‰½κ²Œ μ‚¬μš©ν•  수 μžˆλ‹€.

 

 

β–  예제 : ν™ˆμ”¨μ–΄ν„°

ν™ˆμ”¨μ–΄ν„°μ—λŠ” μ•°ν”„, 슀크린, μ‘°λͺ…, ν”„λ‘œμ ν„°, 팝콘 기계 등이 μ‘΄μž¬ν•œλ‹€.

 

νŒŒμ‚¬λ“œ μ μš©μ „μ˜ ν™ˆμ”¨μ–΄ν„° ꡬ쑰

ν΄λž˜μŠ€κ°€ 맀우 λ§Žλ‹€. 이 ν΄λž˜μŠ€λ“€μ€ μ„œλ‘œ λ³΅μž‘ν•˜κ²Œ μ—°κ²°λ˜μ–΄ 있고, μ œλŒ€λ‘œ μ“°λ €λ©΄ λ§Žμ€ λΉ„μš©μ΄ λ“ λ‹€.

 

 

μ˜ν™”λ₯Ό 보렀면

popconPopper.on(); // 팝콘 기계λ₯Ό μΌ λ‹€.
popconPopper.pop(); // 팝콘 νŠ€κΈ΄λ‹€.
light.dim(20); // μ‘°λͺ…을 20% 둜 μ‘°μ ˆν•œλ‹€.
screen.down(); // μŠ€ν¬λ¦°μ„ λ‚΄λ¦°λ‹€
amp.on(); // μ•°ν”„λ₯Ό μΌ λ‹€
streamingPlayer.play(); // ν”Œλ ˆμ΄μ–΄λ₯Ό μ‹€ν–‰μ‹œν‚¨λ‹€
// 기타 λ™μž‘ (ν”Œλ ˆμ΄μ–΄ μΌμ‹œμ •μ§€, μ‘°λͺ… 쑰절, λ³Όλ₯¨ 쑰절 λ“±)

μ˜ν™”λ₯Ό 끄고 μ •λ¦¬ν•˜λ €λ©΄, μœ„μ˜ λ™μž‘λ“€μ„ μ „λΆ€ μ—­μˆœμœΌλ‘œ ν•΄μ•Όν• κΉŒ? ν™ˆμ”¨μ–΄ν„° μ‹œμŠ€ν…œμ— κΈ°λŠ₯ μΆ”κ°€λ“± μ—…κ·Έλ ˆμ΄λ“œ λœλ‹€λ©΄?

ν™ˆμ”¨μ–΄ν„°λ‘œ μ˜ν™”λ₯Ό λ³΄λŠ” 것이 μ•„λ‹ˆλΌ, TV μ‹œμ²­μ΄λ‚˜ λΌλ””μ˜€ μ²­μ·¨λ₯Ό ν•œλ‹€λ©΄ μ΄λ ‡κ²Œ λ³΅μž‘ν•œ 과정을 ν•΄μ•Όν•˜λŠ”κ°€?

 

μ΄λŸ΄λ•Œ νŒŒμ‚¬λ“œ νŒ¨ν„΄μ„ μ΄μš©ν•˜μž.

 

μΈν„°νŽ˜μ΄μŠ€λ₯Ό λ‹¨μˆœν™” μ‹œν‚€κΈ° μœ„ν•΄ μΈν„°νŽ˜μ΄μŠ€λ₯Ό λ³€κ²½ν•œλ‹€.

 

(1) ν™ˆμ”¨μ–΄ν„°λ₯Ό κ΅¬μ„±ν•˜λŠ” 객체듀

/** μ•°ν”„ */
public class Amplifier {
    String description;
    Tuner tuner;
    StreamingPlayer player;

    public Amplifier(String description) {
        this.description = description;
    }

    public void on() { System.out.println(description + " 전원 on"); }
    public void off() { System.out.println(description + " 전원 off"); }
    public void setStereoSound() { System.out.println(description + " μŠ€ν…Œλ ˆμ˜€ λͺ¨λ“œ on"); }
    public void setSurroundSound() { System.out.println(description + " μ„œλΌμš΄λ“œ λͺ¨λ“œ on"); }
    public void setVolume(int level) { System.out.println(description + " λ³Όλ₯¨ μ„€μ • " + level);}
    public void setTuner(Tuner tuner) {
        System.out.println(description + " νŠœλ„ˆ μ„€μ • " + tuner);
        this.tuner = tuner;
    }

    public void setStreamingPlayer(StreamingPlayer player) {
        System.out.println(description + " set 슀트리밍 ν”Œλ ˆμ΄μ–΄ " + player);
        this.player = player;
    }

    @Override
    public String toString() {
        return "Amplifier{" + "description='" + description + '\'' + '}';
    }
}
/** CD ν”Œλ ˆμ΄μ–΄ */
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 + "\"");
    }

    public void play(int track) {
        if (title == null) {
            System.out.println(description + " μž¬μƒ λΆˆκ°€ " + currentTrack + " cd μ—†μŒ");
        } else {
            currentTrack = track;
            System.out.println(description + " μž¬μƒ 쀑 " + currentTrack);
        }
    }

    public void stop() {
        currentTrack = 0;
        System.out.println(description + " 정지!!");
    }

    public void pause() { System.out.println(description + " μΌμ‹œμ •μ§€ \"" + title + "\""); }

    @Override
    public String toString() {
        return "CdPlayer{" + "description='" + description + '\'' + '}';
    }
}
/** 팝콘 기계 */
public class PopcornPopper {
    String description;

    public PopcornPopper(String description) {
        this.description = description;
    }

    public void on() { System.out.println(description + " on"); }
    public void off() { System.out.println(description + " off"); }
    public void pop() { System.out.println(description + " 팝콘 νŠ€κΈ°κΈ°!!"); }

    @Override
    public String toString() {
        return "PopcornPopper{" + "description='" + description + '\'' + '}';
    }
}
/** ν”„λ‘œμ ν„° */
public class Projector {
    String description;
    StreamingPlayer player;

    public Projector(String description, StreamingPlayer player) {
        this.description = description;
        this.player = player;
    }

    public void on() { System.out.println(description + " 전원 on"); }
    public void off() { System.out.println(description + " 전원 off"); }
    public void wideScreenMode() { System.out.println(description + " μ™€μ΄λ“œ 슀크린 λͺ¨λ“œ (16x9)"); }
    public void tvMode() { System.out.println(description + " tv λͺ¨λ“œ (4x3)"); }

    @Override
    public String toString() {
        return "Projector{" + "description='" + description + '\'' + '}';
    }
}
/** 슀크린 */
public class Screen {
    String description;

    public Screen(String description) {
        this.description = description;
    }

    public void up() { System.out.println(description + " 올리기!"); }
    public void down() { System.out.println(description + " 내리기!"); }

    @Override
    public String toString() {
        return "Screen{" + "description='" + description + '\'' + '}';
    }
}
/** μž¬μƒ ν”Œλ ˆμ΄μ–΄ */
public class StreamingPlayer {
    String description;
    int currentChapter;
    Amplifier amplifier;
    String movie;

    public StreamingPlayer(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 play(String movie) {
        this.movie = movie;
        currentChapter = 0;
        System.out.println(description + " playing \"" + movie + "\"");
    }

    public void stop() {
        currentChapter = 0;
        System.out.println(description + " 정지 \"" + movie + "\"");
    }

    public void pause() {
        System.out.println(description + " μΌμ‹œμ€‘μ§€ \"" + movie + "\"");
    }

    public void setTwoChannelAudio() { System.out.println(description + " set 2ch μŠ€ν…Œλ ˆμ˜€ μ˜€λ””μ˜€"); }
    public void setSurroundAudio() { System.out.println(description + " set μ„œλΌμš΄λ“œ μ˜€λ””μ˜€"); }
        
    @Override
    public String toString() {
        return "StreamingPlayer{" + "description='" + description + '\'' + '}';
    }
}
/** μ‘°λͺ… */
public class TheaterLights {
    String description;

    public TheaterLights(String description) {
        this.description = description;
    }

    public void on() { System.out.println(description + " 전원 on"); }
    public void off() { System.out.println(description + " 전원 off"); }
    public void dim(int level) { System.out.println(description + " μ‘°μ • to " + level + " %"); }

    @Override
    public String toString() {
        return "TheaterLights{" + "description='" + description + '\'' + '}';
    }
}
/** νŠœλ„ˆ */
public class Tuner {
    String description;
    Amplifier amplifier;
    double frequency;

    public Tuner(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 setFrequency(double frequency) {
        System.out.println(description + " 주파수 μ„€μ • " + frequency);
        this.frequency = frequency;
    }

    public void setAm() { System.out.println(description + " set AM mode"); }
    public void setFm() { System.out.println(description + " set FM mode"); }

    @Override
    public String toString() {
        return "Tuner{" + "description='" + description + '\'' + '}';
    }
}

(2) νŒŒμ‚¬λ“œ λ§Œλ“€κΈ°

public class HomeTheaterFacade {
    Amplifier amplifier;
    CdPlayer cdPlayer;
    PopcornPopper popcornPopper;
    Projector projector;
    Screen screen;
    StreamingPlayer streamingPlayer;
    TheaterLights theaterLights;
    Tuner tuner;
    
    // constructor
    public HomeTheaterFacade(Amplifier amplifier, CdPlayer cdPlayer, 
                            PopcornPopper popcornPopper, Projector projector, Screen screen, 
                            StreamingPlayer streamingPlayer, TheaterLights theaterLights, Tuner tuner) {
        this.amplifier = amplifier;
        this.cdPlayer = cdPlayer;
        this.popcornPopper = popcornPopper;
        this.projector = projector;
        this.screen = screen;
        this.streamingPlayer = streamingPlayer;
        this.theaterLights = theaterLights;
        this.tuner = tuner;
    }

    public void watchMovie(String movie) {
        System.out.println("===== μ˜ν™” 보기 =====");
        popcornPopper.on();
        popcornPopper.pop();
        theaterLights.dim(10);
        screen.down();
        projector.on();
        projector.wideScreenMode();
        amplifier.on();
        amplifier.setStreamingPlayer(streamingPlayer);
        amplifier.setSurroundSound();
        amplifier.setVolume(5);
        streamingPlayer.on();
        streamingPlayer.play(movie);
    }

    public void endMovie() {
        System.out.println("===== μ˜ν™” 끝 =====");
        popcornPopper.off();
        theaterLights.on();
        screen.up();
        projector.off();
        amplifier.off();
        streamingPlayer.stop();
        streamingPlayer.off();
    }

    public void listenToRadio(double frequency) {
        System.out.println("===== λΌλ””μ˜€ λ“£κΈ° =====");
        tuner.on();
        tuner.setFrequency(frequency);
        amplifier.on();
        amplifier.setVolume(6);
        amplifier.setTuner(tuner);
    }

    public void endRadio() {
        System.out.println("===== λΌλ””μ˜€ μ’…λ£Œ =====");
        tuner.off();
        amplifier.off();
    }
}

(3) μ‹€ν–‰

@Test
void homeTheaterPlayMovie() {
    Amplifier amplifier = new Amplifier("μ•°ν”„");
    Tuner tuner = new Tuner("Am/Fm νŠœλ„ˆ", amplifier);
    StreamingPlayer streamingPlayer = new StreamingPlayer("슀트리밍 ν”Œλ ˆμ΄μ–΄", amplifier);
    CdPlayer cdPlayer = new CdPlayer("CD ν”Œλ ˆμ΄μ–΄", amplifier);
    Projector projector = new Projector("ν”„λ‘œμ ν„°", streamingPlayer);
    TheaterLights theaterLights = new TheaterLights("μ‘°λͺ… 라이트");
    Screen screen = new Screen("슀크린");
    PopcornPopper popcornPopper = new PopcornPopper("팝콘 팝팝!");
    // νŒŒμ‚¬λ“œ 생성
    HomeTheaterFacade homeTheaterFacade = new HomeTheaterFacade(amplifier, cdPlayer, popcornPopper, projector,
            screen, streamingPlayer, theaterLights, tuner);
    // μ˜ν™”λ³΄κΈ°
    homeTheaterFacade.watchMovie("기생좩");
    homeTheaterFacade.endMovie();
 }

@Test
void homeTheaterPlayRadio() {
    Amplifier amplifier = new Amplifier("κ³¨λ“œ μ•°ν”„");
    Tuner tuner = new Tuner("λΌλ””μ˜€ νŠœλ„ˆ", amplifier);
    StreamingPlayer streamingPlayer = new StreamingPlayer("μž¬μƒ ν”Œλ ˆμ΄μ–΄", amplifier);
    CdPlayer cdPlayer = new CdPlayer("CD player", amplifier);
    Projector projector = new Projector("콀팩트 ν”„λ‘œμ ν„°", streamingPlayer);
    TheaterLights theaterLights = new TheaterLights("νœ΄λŒ€μš© μ‘°λͺ…");
    Screen screen = new Screen("νœ΄λŒ€μš© 슀크린");
    PopcornPopper popcornPopper = new PopcornPopper("팝콘!");
    // νŒŒμ‚¬λ“œ 생성
    HomeTheaterFacade homeTheaterFacade = new HomeTheaterFacade(amplifier, cdPlayer, popcornPopper, projector,
            screen, streamingPlayer, theaterLights, tuner);
    // λΌλ””μ˜€ λ“£κΈ°
    homeTheaterFacade.listenToRadio(107.7);
    homeTheaterFacade.endRadio();
}

(4) κ²°κ³Ό 확인

===== μ˜ν™” 보기 =====
팝콘 팝팝! on
팝콘 팝팝! 팝콘 νŠ€κΈ°κΈ°!!
μ‘°λͺ… 라이트 μ‘°μ • to 10 %
슀크린 내리기!
ν”„λ‘œμ ν„° 전원 on
ν”„λ‘œμ ν„° μ™€μ΄λ“œ 슀크린 λͺ¨λ“œ (16x9)
μ•°ν”„ 전원 on
μ•°ν”„ set 슀트리밍 ν”Œλ ˆμ΄μ–΄ StreamingPlayer{description='슀트리밍 ν”Œλ ˆμ΄μ–΄'}
μ•°ν”„ μ„œλΌμš΄λ“œ λͺ¨λ“œ on
μ•°ν”„ λ³Όλ₯¨ μ„€μ • 5
슀트리밍 ν”Œλ ˆμ΄μ–΄ 전원 on
슀트리밍 ν”Œλ ˆμ΄μ–΄ playing "기생좩"

===== μ˜ν™” 끝 =====
팝콘 팝팝! off
μ‘°λͺ… 라이트 전원 on
슀크린 올리기!
ν”„λ‘œμ ν„° 전원 off
μ•°ν”„ 전원 off
슀트리밍 ν”Œλ ˆμ΄μ–΄ 정지 "기생좩"
슀트리밍 ν”Œλ ˆμ΄μ–΄ 전원 off

===== λΌλ””μ˜€ λ“£κΈ° =====
λΌλ””μ˜€ νŠœλ„ˆ 전원 on
λΌλ””μ˜€ νŠœλ„ˆ 주파수 μ„€μ • 107.7
κ³¨λ“œ μ•°ν”„ 전원 on
κ³¨λ“œ μ•°ν”„ λ³Όλ₯¨ μ„€μ • 6
κ³¨λ“œ μ•°ν”„ νŠœλ„ˆ μ„€μ • Tuner{description='λΌλ””μ˜€ νŠœλ„ˆ'}

===== λΌλ””μ˜€ μ’…λ£Œ =====
λΌλ””μ˜€ νŠœλ„ˆ 전원 off
κ³¨λ“œ μ•°ν”„ 전원 off

 

 

νŒŒμ‚¬λ“œλ₯Ό λ§Œλ“€μ–΄ μ„œλΈŒν΄λž˜μŠ€λ“€μ„ ν†΅ν•©μ‹œν‚¨ 과정을 그림으둜 ν‘œν˜„ν•˜λ©΄ λ‹€μŒκ³Ό κ°™λ‹€.

λ³΅μž‘ν•œ μ„œλΈŒ ν΄λž˜μŠ€λ“€μ„ ν†΅ν•©ν•˜λŠ” νŒŒμ‚¬λ“œ 클래슀λ₯Ό λ§Œλ“€μ—ˆλ‹€.

νŒŒμ‚¬λ“œ ν΄λž˜μŠ€λŠ” μ„œλΈŒ ν΄λž˜μŠ€λ“€μ„ μΊ‘μŠν™” ν•˜λŠ” 것이 μ•„λ‹ˆλ‹€. κ·Έλƒ₯ μ„œλΈŒ ν΄λž˜μŠ€λ“€μ˜ κΈ°λŠ₯을 μ‚¬μš©ν•  수 μžˆλŠ” κ°„λ‹¨ν•œ μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ œκ³΅ν•˜λŠ” 것 뿐이닀. λ”°λΌμ„œ ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ νŠΉμ • μ„œλΈŒμ‹œμŠ€ν…œ 클래슀λ₯Ό κ·Έλƒ₯ μ‚¬μš©ν• μˆ˜λ„ μžˆλ‹€.

νŒŒμ‚¬λ“œλŠ” νŒ¨ν„΄μ„ μ‚¬μš©ν•˜λ©΄ μΈν„°νŽ˜μ΄μŠ€λ₯Ό λ‹¨μˆœν™”μ‹œν‚¬ 뿐 μ•„λ‹ˆλΌ ν΄λΌμ΄μ–ΈνŠΈ κ΅¬ν˜„κ³Ό μ„œλΈŒμ‹œμŠ€ν…œμ„ λΆ„λ¦¬μ‹œν‚¬ 수 μžˆλ‹€. 이 λ•Œλ¬Έμ— ν™ˆμ”¨μ–΄ν„°μ˜ 기계가 λ°”λ€Œμ–΄λ„, ν΄λΌμ΄μ–ΈνŠΈλŠ” μˆ˜μ •ν•˜μ§€μ•Šκ³  νŒŒμ‚¬λ“œλ§Œ μˆ˜μ •ν•¨μœΌλ‘œμ¨ 기계 κ΅ν™˜μ΄ κ°€λŠ₯해진닀. 

 

β–  μ΅œμ†Œ 지식 원칙

λ³΅μž‘ν•˜κ³  λ§Žμ€ μ„œλΈŒ ν΄λž˜μŠ€λ“€ (ν™ˆμ”¨μ–΄ν„°μ˜ 각쒅 κΈ°κΈ°λ“€) 을 λ‹¨μˆœν™”ν•˜κ³  ν†΅ν•©ν•œ 클래슀λ₯Ό λ§Œλ“€μ–΄ νŒŒμ‚¬λ“œ νŒ¨ν„΄μ„ μ™„μ„±ν–ˆλ‹€.

이제 ν΄λΌμ΄μ–ΈνŠΈμ™€ μ„œλΈŒ μ‹œμŠ€ν…œμ΄ μ„œλ‘œ κΈ΄λ°€ν•˜κ²Œ μ—°κ²°λ˜μ§€ μ•Šμ•„λ„ 되고, μ΅œμ†Œ 지식 원칙을 μ€€μˆ˜ν•˜λŠ”λ° 도움을 μ€€λ‹€.

πŸ“Œ μ΅œμ†Œ 지식 원칙
정말 μΉœν•œ μΉœκ΅¬ν•˜κ³ λ§Œ μ–˜κΈ°ν•˜λΌ!

μ–΄λ–€ 객체든 κ·Έ 객체와 μƒν˜Έμž‘μš©ν•˜λŠ” 클래슀의 κ°œμˆ˜μ— μ£Όμ˜ν•΄μ•Όν•˜λ©°, μ–΄λ–€μ‹μœΌλ‘œ μƒν˜Έμž‘μš©ν•˜λŠ”μ§€λ„ 주의λ₯Ό κΈ°μšΈμ—¬μ•Ό ν•œλ‹€λŠ” μ˜λ―Έμ΄λ‹€.

즉, μ–΄λ–€ λ©”μ†Œλ“œμ—μ„œλ“ μ§€ μ•„λž˜μ˜ λ„€ μ’…λ₯˜μ˜ 객체 λ©”μ†Œλ“œλ§Œ ν˜ΈμΆœν•˜μž!

  1. 객체 자체
  2. λ©”μ†Œλ“œμ— λ§€κ°œλ³€μˆ˜λ‘œ μ „λ‹¬λœ 객체
  3. κ·Έ λ©”μ†Œλ“œμ—μ„œ μƒμ„±ν•˜κ±°λ‚˜ μΈμŠ€ν„΄μŠ€λ₯Ό λ§Œλ“  객체
  4. κ·Έ 객체에 μ†ν•˜λŠ” κ΅¬μ„±μš”μ†Œ

Without the Principle

public float getTemp() {
    // stationμœΌλ‘œλΆ€ν„° ThermometerλΌλŠ” 객체λ₯Ό λ°›μ€λ‹€μŒ
    Thermometer thermometer = station.getThermometer();
    // κ·Έ 객체의 getTemperature()λ©”μ†Œλ“œλ₯Ό 직접 호좜
    return thermometer.getTemperature();
}

With the Principle

public float getTemp() {
    // Station ν΄λž˜μŠ€μ— thermometer에 μš”μ²­μ„ ν•΄μ£ΌλŠ” λ©”μ†Œλ“œλ₯Ό μΆ”κ°€
    // μ΄λ ‡κ²Œν•˜λ©΄ μ˜μ‘΄ν•΄μ•Όν•˜λŠ” 클래슀의 개수λ₯Ό μ€„μΌμˆ˜ μžˆλ‹€.
    return station.getTemperature();
}

λ©”μ†Œλ“œ ν˜ΈμΆœμ„ λ°”μš΄λ”λ¦¬ μ•ˆμ—μ„œ μœ μ§€ν•˜λ„λ‘ ν•˜μž.

public class Car {
    // 이 클래슀의 κ΅¬μ„±μš”μ†Œ, 이 κ΅¬μ„±μš”μ†Œμ˜ λ©”μ†Œλ“œλŠ” 호좜 OK
    Engine engine; 
    // λ‹€λ₯Έ μΈμŠ€ν„΄μŠ€ λ³€μˆ˜λ“€...

    public Car() { // Constructor
        // μΈμŠ€ν„΄μŠ€ λ³€μˆ˜λ“€ μ΄ˆκΈ°ν™”
    }

    // λ§€κ°œλ³€μˆ˜λ‘œ μ „λ‹¬λœ 객체(Key)의 λ©”μ†Œλ“œλŠ” 호좜 OK
    public void start(Key key) {
        // μƒˆλ‘œμš΄ 객체 생성. 이 객체의 λ©”μ†Œλ“œλŠ” 호좜 OK
        Doors doors = new Doors();
        // λ§€κ°œλ³€μˆ˜λ‘œ μ „λ‹¬λœ 객체(Key)의 λ©”μ†Œλ“œλŠ” 호좜 OK
        boolean authorized = key.turns();

        if(authorized) {
            engine.start(); // κ΅¬μ„±μš”μ†Œμ˜ 객체의 λ©”μ†Œλ“œλŠ” 호좜 OK
            updateDashboardDisplay(); // 객체 λ‚΄μ˜ 둜컬 λ©”μ†Œλ“œ 호좜 OK
            doors.lock(); // 직접 μƒμ„±ν•˜κ±°λ‚˜ μΈμŠ€ν„΄μŠ€λ₯Ό λ§Œλ“  객체의 λ©”μ†Œλ“œ 호좜 OK
        }
    }

    public void updateDashboardDisplay() {
        // μ—…λ°μ΄νŠΈ display λ‚΄μš©
    }
}

 

β–  UML Diaglam

 

 


μ°Έκ³ 
ν—€λ“œ 퍼슀트 λ””μžμΈ νŒ¨ν„΄ (Head First Design Patterns) - 에릭 프리먼,μ—˜λ¦¬μžλ² μŠ€ 둭슨,μΌ€μ΄μ‹œ μ‹œμ—λΌ,λ²„νŠΈ 베이츠

 

λ°˜μ‘ν˜•