0. 개요
Pattern이란 'proven solution' to a problem that recurs in a particular context
- pattern은 invented 되는 것이 아니라 discovered 되는 것 (이미 존재하는 것을 찾아서 가져다 쓰는 것!)
- 이런 문제에 이런 패턴을 쓰면 좋더라라는 경험을 기반으로 재사용하는 것
Summary
ⓐ 디자인 패턴은 경험적으로 검증된 해결 방법들
ⓑ 개발자들이 자신의 특수한 문제에 적용할 수 있도록 일반적인 설계 문제에 대한 아이디어를 구조적이고 재사용 가능한 방식으로 제공
1. Design Pattern
1) Pattern Template
: 일반적으로 패턴은 다음의 항목을 포함한다. 개발자는 패턴 템플릿을 참고하여 자신의 문제에 적합한 디자인 패턴을 고르도록 한다. (무분별하게 가져다 쓰지 말 것)
- Name : 패턴을 대표하는 meaningful word를 사용
- Problem : 패턴이 다루는 문제에 대한 설명
- Solution : description of static & dynamic relationships among components of pattern
- 샘플 코드와 활용 예시
- 유사한 패턴
2) GOF Design Pattern
catalogue of 23 design patterns
① Creational Pattern
② Structural Pattern
③ Behavioral Pattern
2. Creational Patterns
: concerned with the construction of object instance
1) Singleton
How can we ensure that only one instance of class is created?
- restrict access to constructor!
(첫번 째 호출된 생성자만 객체를 생성하고, 그 이후에는 객체를 생성하지않도록 할 것)
3. Structural Patterns
: concerned with the way in which classes and objects are organized
1) Composite (<> primitive)
How can we present the same interface for collection(composite) 's different component?
즉 여러 class의 object로 구성된 composite을 하나의 인터페이스를 사용해 (어떤 class의 object인지와 무관하게) 나타내고자 한다면?
4. Behavioural Patterns
: considering when assigning responsibilities to classes and when designing algorithms
즉 동일한 동작을 상태에 따라 다르게 처리해야 할 때
- State Machine
- another way