본문 바로가기
SW 공부/Design Patterns

[디자인패턴] Adapter pattern (어댑터 패턴)

by 꼬냉상 2022. 8. 28.

Purpose of Adapter Pattern (어댑터 패턴의 목적)

aka) Wrapper

- Permits classes with different interfaces to work together by creating a common object by which they may communicate and interact.

- 서로 다른 인터페이스를 가진 클래스가 통신하고 상호 작용할 수 있는 공통 개체를 만들어 함께 작동하도록

 

Adapter pattern (어댑터 패턴)

- Converts the interface of a class into another interface clients expect.

- 클래스의 인터페이스를 클라이언트가 기대하는 다른 인터페이스로 변환

- Mechanism 
 → Client가 Adapter에세 calling method를 써서 target interface를 쓰도록 요청

 → Adapteradaptee interface를 써서 translate the request call 처리

- Object Adapter : uses object composition and delegation

- Class Adapter : uses inheritance

Quiz) 아래 설계된 EnumerationIterator의 반대 작용을 하는 Adapter를 만드시오. 즉, 클라이언트는 Enumeration을 target interface로 기대하고 있으나 실제 벤더의 구현은 Iterator 인터페이스를 따를 때, 이를 위한 Adapter의 클래스 다이어그램을 제시하시오.

 → target interface를 Enumeration 로 변경하고, adaptee interface를 Iterator로 활용하도록 변경

본 글은 개인의 S/W 구조설계 역량 강화를 위한 학습 목적으로 정리된 내용입니다.
일부 타/개인 단체에 저작권이 있는 자료를 포함하고 있으므로, 절대 영리 목적으로 사용하실 수 없습니다.

 

반응형

댓글