티스토리 뷰

Design Pattern

퍼사드 패턴

Seogineer 2021. 3. 13. 21:04

퍼사드 패턴(Facade Pattern)

  • 하나의 인터페이스에서 복잡한 서브시스템을 통합하여 동작시킬 수 있도록 제공해주는 패턴
  • 퍼사드 객체가 클래스 라이브러리 같은 어떤 소프트웨어의 다른 커다란 코드 부분에 대한 간략화된 인터페이스를 제공한다.
  • 실제 사용 예 : Spring에서 Controller

구조

 

예제 소스 코드

/* 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();
	}
}

 

참고

 

퍼사드 패턴

위키백과, 우리 모두의 백과사전.

ko.wikipedia.org

 

Cory's Developing & Life.

Cory's Developing & Life.

kscory.com

 

댓글
Total
Today
Yesterday
링크
Apple 2023 맥북 프로 14 M3, 스페이스 그레이, M3 8코어, 10코어 GPU, 512GB, 8GB, 한글