Java
디자인 패턴 1 - 파사드 패턴(facade pattern)
taehyun_kim
2019. 3. 3. 00:14
Facade란?
건물의 외간이란 뜻이다.
Facade Pattern
다른 인터페이스들을 통합하여 단순화 시킬 때 사용하는 패턴이다.
아래는 컴퓨터가 켜질 때 필요한 동작들을 하나의 인터페이스에 정의한 예제이다.
/* Complex parts */ class CPU { public void freeze() { ... } public void jump(long position) { ... } public void execute() { ... } } class Memory { public void load(long position, byte[] data) { ... } } class HardDrive { public byte[] read(long lba, int size) { ... } } /* Façade */ class Computer { public void startComputer() { CPU cpu = new CPU(); Memory memory = new Memory(); HardDrive hardDrive = new HardDrive(); cpu.freeze(); memory.load(BOOT_ADDRESS, hardDrive.read(BOOT_SECTOR, SECTOR_SIZE)); cpu.jump(BOOT_ADDRESS); cpu.execute(); } } /* Client */ class You { public static void main(String[] args) throws ParseException { Computer facade = /* grab a facade instance */; facade.startComputer(); } }
어댑터 패턴과 데코레이터 패턴과 비슷한거 같은데
다음 포스팅에 정리해보겠습니다.