22
Proxy, Chain of Responsibility, Command Structural & Behavioral Pattern

Proxy, chain of responsibility, command pattern

Embed Size (px)

Citation preview

Proxy,Chain of Responsibility,

Command

Structural & Behavioral Pattern

Content

• Proxy

• Summery (Structural pattern)

• Behavioral pattern

• Chain of responsibility

• Command

Proxy

Surrogate

다른객체에대한대리접근

Motive & Available

• 객체생성에비용이많이드는경우

• 문서편집기의이미지등

• 객체에대한정교한접근자제공

1. 원격지프록시

2. 가상프록시

3. 보호용프록시

4. 스마트참조자

Structure & Contributor

• 실제객체에접근하는참조자관리• 실제객체를대체함• 실제객체의생성및삭제

RealSubject, Proxy에공통적인인터페이스정의

실제객체임

Effect

• 실제객체에대한추가적인간접화방법제공

• 원격프록시 : 저장위치은닉

• 가상프록시 : 생성시점최적화

• 보호프록시 : 엄격한접근

• Copy-On-Write 기법

• 원본을수정해야하는경우에만복사작업진행

• 원본에대한 reference count를관리

Implement

• *, -> 연산자오버로딩

• ex) Image ImagePtr

• 프록시가실제객체를알필요는없음

• 가상프록시의경우실제객체에접근할때에만실제객체필요

• 실제객체의식별자부여

Summery

Structural Pattern

Adapter vs Bridge

• Adapter는인터페이스불일치해소가목적

• Bridge는구현을분리하고인터페이스를통일하는것이목적

• 개발시점차이

• 설계이전 : Bridge

• 설계이후 : Adapter

• Facade?

• 인터페이스를일치시키는것이아님새로운인터페이스작성

Composite, Decorator, Proxy

• Composite, Decorator는재귀적합성사용, 서로다른목적

• Decorator : 상속없이기능추가

• Composite : 객체집합에대한일괄제어

• 상호보완작용

• Composite Leaf : Decorator

• Decorator ConcreteComponent : Component

• Proxy? Decorator?• 객체에대한동일한인터페이스제공• Proxy는참조자관리

Behavioral pattern

행동클래스패턴

행동객체패턴

Behavioral pattern

• 행동클래스패턴

• Template method

• Interpreter

• 행동객체패턴

• Chain of responsibility

• Command

• Iterator

• Observer• State• Strategy• Visitor• Mediator• Memento

Chain of responsibility

메시지송신/수신객체분리

Motive & Available

• 메시지송신측과수신측분리

• 송신/수신객체가여럿일때

• 여러수신자를순회하되수신자를확정할수있을때

• 익명처리

• 수신자집합이동적으로구성될때

Structure & Contributor

처리자인터페이스정의후속처리자연결

메시지처리실패시후속처리자에게요청

Effect

• 객체간행동적결합도를낮춤

• 동적으로처리자연결

• 메시지가버려질수있음

Implement

• 후속처리자연결고리구현

• 새롭게연결고리구현 / 덧붙이기

• 추가연결정보구현

• 후속처리자연결

• 처리요청의표현부정의

• 요청내용의클래스화

• 요청에대한식별자정의

Command

↓↘→↘↓↙← + P

Motive & Available

• 요청을캡슐화

• 요청에대한인터페이스통일, 순차실행등

• 수행할동작을매개변수화(Callback)

• 특정요청의예약실행

• 실행취소 & 로깅

Structure & Contributor

연산수행에필요한인터페이스

receiver와연결

요청자

수신자

Effect

• 연산을호출하는측과연산의주체를분리

• Command를상속하여조작하거나확장

• 여러 Command를묶어서복합 Command를구현

• Command의추가용이

Implement

• 명령이얼마나지능적이어야할까?

• 요청자↔ 수신자간연결기능지원 / 독립실행

• 취소 / 반복연산지원여부

• 수신객체, 매개변수및이전상태

• 취소연산의정확성보장

• 취소후상태검사

• 상황에맞는 Command 사용

• 는 template를사용