반응형
    Purpose
    Defer Object creation to another class or object Describe ways to assemble objects Address problems of assigning responsibilities
    Creational (생성) Structural (구조) Behavioral (행동)
Scope Class Factory Method Adapter Interpreter
Template
Object Abstract Factory
Builder
Prototype
Singleton
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
CoR
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor

스토리

B: 클라이언트가 이용하려는 클래스

A: B의 부모 클래스

- 클라이언트가 B 클래스를 이용하고 있다.

- 이 때, B 클래스 이용을, 기획자는 통제하고 싶다. 하지만, 이때, B클래스 어떠한 변경 사항도 없어야한다.

- 이럴 때, 중간에 통제할 수 있는 클래스가 필요하다. 이것을 C라고하자.

- 결국, C 클래스는 A클래스의 모든 메서드를 통제해야한다. 즉, 같은 메서드에 대해서, 다른 기능을 하게 하고 싶다.

- 하지만 A를 이용하는 클라이언트들의 동작은 같게하고 싶다. 변경을 최소화 하고 싶다.

 

그럴 때 프록시패턴을 이용해서, 프록시클래스로 씌워준다. 아래와 같이.

 

구조 (클래스다이어그램)

오브젝트 다이어그램

doSomething(new MySynchronizedList(new MyArrayList()));

doSomething(new MySynchronizedList(new MyLinkedList()));

 

 

반응형