SlideShare a Scribd company logo
1 of 66
Download to read offline
Design Patterns
데브루키 스터디
발표자 느루
이 피피티는 Head First Design Patterns
책을 참고하여 만들었습니다
활용 예는 부적절할 수도 있습니다
디자인 패턴이란?
- 과거의 소프트웨어 개발 과정에서 발견된
설계의 노하우를 정리하여 이름을 붙인 것
- 자주 발생하는 문제에 대한 검증된 해결책을
의미한다
디자인 패턴을 사용하는 이유
여러 사람들에 의해서 검증된 방법
디자인 패턴을 사용하는 이유
복잡한 구조를 한 단어로 정의함으로써
의사소통을 효율적으로 할 수 있다
A : 노랗고 동그랗고
안경을 낀데다가 바나나를
좋아하는 캐릭터가
말이죠…
B : 미니언이요?
목차
- Strategy
- Observer
- Decorator
- Factory Method
- Abstract Factory
- Singleton
- Command
샘플코드
https://github.com/include8/HFDP
Strategy 패턴
Strategy 패턴
- 알고리즘을 캡슐화하여 교체하여 사용 할 수
있도록 한 구조
- 알고리즘 인터페이스를 정의하고
인터페이스를 상속받은 클래스에 알고리즘을
구현하여 캡슐화
- 알고리즘을 사용할 클래스에 인터페이스를
포함시킨다
Strategy 패턴
Strategy 패턴 예제
Strategy 패턴 예제
이후에 이 프로그래머가
C++ 클라이언트 프로그래머로 바뀌어야
한다면?
Strategy 패턴 예제
Strategy 패턴 예제
Strategy 패턴 예제
Strategy 패턴의 장단점
- 상속으로 해결 할 수 없는 코드 중복이나
객체의 실시간 알고리즘의 변경 시에
유용하다
- 신규 알고리즘 추가, 수정이 용이하다
- OPP 디자인적인 관점에 맞지 않다
Strategy 패턴, 언제 사용할까?
- 게임 룰을 모드 별로 다르게 적용하고 싶을
때
- 상황에 따라 길찾기 알고리즘을 바꾸고 싶을
때
Observer 패턴
Observer 패턴
- 객체의 상태변화를 관찰하는 관찰자들을
객체가 가지고 있다가 상태변화가 있을 시
통지하는 패턴
- 일대다(one-to-many) 의존성을 정의한다
Observer 패턴
Observer 패턴 예제
이때 구독자의 종류와 수를 자유롭게
추가하고자 하려면?
Observer 패턴 예제
Observer 패턴 예제
Observer 패턴 예제
Observer 패턴 장단점
- 느슨한 결합으로 옵저버가 추가되어도 주제
객체는 수정을 하지 않아도 된다
- 구독을 취소하는 동안에는 통지를 받을 수
없다
Observer 패턴, 언제 사용할까?
- GUI
- 채팅 프로그램
Decorator 패턴
Decorator 패턴
- 객체에 추가적인 요건을 동적으로 첨가하는
패턴
- 기본 클래스의 서브 클래스를 구성하여
생성시 상속받은 클래스를 넘겨서 확장할 수
있도록 함
Decorator 패턴
Decorator 패턴 예제
손님이 즉석에서 원하는 재료로 피자를
주문하기를 원한다면?
Decorator 패턴 예제
Decorator 패턴 예제
Decorator 패턴 예제
Decorator 패턴 장단점
- 동적으로 클래스 확장이 가능하다
- 잡다한 클래스들이 많아질 수 있다
- 데코레이터로싸인 객체를 알기 힘들다
Decorator 패턴, 언제 사용할까?
- 자바 I/O
Factory 패턴
Factory 패턴
- 객체 생성을 캡슐화한 패턴
- 객체 생성작업과 사용작업을 분리시켜준다
Factory Method 패턴
- 객체 생성을 담당하는 인터페이스를
만들어서 그 인터페이스를 상속받은
클래스에서 객체생성을 구현
Factory Method 패턴
Factory Method 패턴 예제
Abstract Factory 패턴
- 팩토리 인터페이스를 만듬으로써 사용자가
구상클래스에 의존하지 않고 객체를 생성할
수 있도록 해준다
Abstract Factory 패턴 예제
Abstract Factory 패턴 예제
Factory 패턴 장단점
- 새로운 객체가 추가되더라도 소스의 수정이
없다
- 객체 생성을 한 군데서 하는 이상 동일한
생성을 보장한다
- 생성하는 객체의 양이 적다면 코드를
복잡하게 만들 수 있다
Factory 패턴, 언제 사용할까?
- 객체를 동적으로 생성 할 때
Singleton 패턴
https://youtu.be/nGB1ccGf2HA?t=57s
Singleton 패턴
- 프로그램 내에서 인스턴스가 하나만
존재해야하고 어디에서든 인스턴스에 접근할
수 있도록 해주는 패턴
Singleton 패턴
Singleton 패턴 예제
Singleton 패턴 장단점
- 객체 생성 횟수를 줄일 수 있다
- 전역변수와 달리 사용하기 전까지 객체가
생성되지 않는다
- 멀티 스레드 환경에서 사용시 동기화를
보장해주지 않는다
Singleton 패턴, 언제 사용할까?
- 로그기록 객체
- 유저 매니저
- 데이터 테이블정보를 저장하는 클래스
Command 패턴
Command 패턴
- 요청을 객체의 형태로 캡슐화한 패턴
- 서로 요청이 다른 사용자의 매개변수, 요청
저장, 로깅, 연산 취소를 지원한다
Command 패턴
Command 패턴 예제
Command 패턴 예제
캐릭터의 액션 내역을 저장해서 되돌리고
싶다면?
Command 패턴 예제
Command 패턴 예제
Command 패턴 예제
Command 패턴 장단점
- 작업을 요청하는 객체와 실제 작업을 하는
객체를 분리 시킨다
- 다양한 요구를 쉽게 추가할 수 있다
- 자잘한 클래스가 많이 생성된다
Command 패턴, 언제 사용할까?
- 편집기의 실행취소 기능
번외
패턴은 다른 패턴과 함께 사용하기도 합니다
Singleton Factory 패턴
예제
출처
- 헤드 퍼스트 디자인 패턴 (한빛미디어)
- http://hongjinhyeon.tistory.com/
- http://tiboy.tistory.com/
- http://zetawiki.com/wiki/
- https://en.wikipedia.org
- http://gameprogrammingpatterns.com/
- 기타 등등..
Q & A

More Related Content

What's hot

08 virtual memory
08 virtual memory08 virtual memory
08 virtual memory
Kamal Singh
 
Construcţia tiparului de bază pentru bluza de femei cu pensă de bust şi talie
Construcţia tiparului de bază pentru bluza de  femei cu pensă de bust şi talieConstrucţia tiparului de bază pentru bluza de  femei cu pensă de bust şi talie
Construcţia tiparului de bază pentru bluza de femei cu pensă de bust şi talie
Geanina Predatu
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
C.U
 

What's hot (20)

08 virtual memory
08 virtual memory08 virtual memory
08 virtual memory
 
Rational Unified Process
Rational Unified ProcessRational Unified Process
Rational Unified Process
 
Uml
UmlUml
Uml
 
SAD11 - Sequence Diagrams
SAD11 - Sequence DiagramsSAD11 - Sequence Diagrams
SAD11 - Sequence Diagrams
 
Deadlock
DeadlockDeadlock
Deadlock
 
Rational Unified Process
Rational Unified ProcessRational Unified Process
Rational Unified Process
 
Construcţia tiparului de bază pentru bluza de femei cu pensă de bust şi talie
Construcţia tiparului de bază pentru bluza de  femei cu pensă de bust şi talieConstrucţia tiparului de bază pentru bluza de  femei cu pensă de bust şi talie
Construcţia tiparului de bază pentru bluza de femei cu pensă de bust şi talie
 
Metodologia omt
Metodologia omtMetodologia omt
Metodologia omt
 
Page replacement
Page replacementPage replacement
Page replacement
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Open MPI
Open MPIOpen MPI
Open MPI
 
Operating Systems - memory management
Operating Systems - memory managementOperating Systems - memory management
Operating Systems - memory management
 
CS8494 SOFTWARE ENGINEERING Unit-3
CS8494 SOFTWARE ENGINEERING Unit-3CS8494 SOFTWARE ENGINEERING Unit-3
CS8494 SOFTWARE ENGINEERING Unit-3
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
Ch5 process synchronization
Ch5   process synchronizationCh5   process synchronization
Ch5 process synchronization
 
Fundamentals Of Software Architecture
Fundamentals Of Software ArchitectureFundamentals Of Software Architecture
Fundamentals Of Software Architecture
 
Architecture design in software engineering
Architecture design in software engineeringArchitecture design in software engineering
Architecture design in software engineering
 
Spiral model
Spiral modelSpiral model
Spiral model
 
Software Engineering : Requirement Analysis & Specification
Software Engineering : Requirement Analysis & SpecificationSoftware Engineering : Requirement Analysis & Specification
Software Engineering : Requirement Analysis & Specification
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 

Similar to 디자인패턴

HolubOnPatterns/chapter2_2
HolubOnPatterns/chapter2_2HolubOnPatterns/chapter2_2
HolubOnPatterns/chapter2_2
SeungHyun Hwang
 
프로토타이핑
프로토타이핑프로토타이핑
프로토타이핑
정인 주
 
Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기
Daum DNA
 
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
Hyun-Soo Ji
 
Refactoring tutorial
Refactoring tutorialRefactoring tutorial
Refactoring tutorial
Bingu Shim
 

Similar to 디자인패턴 (20)

Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
[Dev rookie]designpattern
[Dev rookie]designpattern[Dev rookie]designpattern
[Dev rookie]designpattern
 
Create a solution including deep learning models
Create a solution including deep learning modelsCreate a solution including deep learning models
Create a solution including deep learning models
 
HolubOnPatterns/chapter2_2
HolubOnPatterns/chapter2_2HolubOnPatterns/chapter2_2
HolubOnPatterns/chapter2_2
 
Design pattern 4
Design pattern 4Design pattern 4
Design pattern 4
 
프로토타이핑
프로토타이핑프로토타이핑
프로토타이핑
 
Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기
 
Patterns for effectviely documenting frameworks
Patterns for effectviely documenting frameworksPatterns for effectviely documenting frameworks
Patterns for effectviely documenting frameworks
 
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
 
디자인패턴 1~13
디자인패턴 1~13디자인패턴 1~13
디자인패턴 1~13
 
Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Let'Swift 2023 Swift Macro, 어디다 쓰죠?
Let'Swift 2023 Swift Macro, 어디다 쓰죠?Let'Swift 2023 Swift Macro, 어디다 쓰죠?
Let'Swift 2023 Swift Macro, 어디다 쓰죠?
 
Prototyping
PrototypingPrototyping
Prototyping
 
딥러닝 세계에 입문하기 위반 분투
딥러닝 세계에 입문하기 위반 분투딥러닝 세계에 입문하기 위반 분투
딥러닝 세계에 입문하기 위반 분투
 
검색엔진에 적용된 ChatGPT
검색엔진에 적용된 ChatGPT검색엔진에 적용된 ChatGPT
검색엔진에 적용된 ChatGPT
 
개발자, 성장하는 '척' 말고, 진짜 성장하기
개발자, 성장하는 '척' 말고, 진짜 성장하기개발자, 성장하는 '척' 말고, 진짜 성장하기
개발자, 성장하는 '척' 말고, 진짜 성장하기
 
애자일과 애자일 테스트 소개 (테스트기본교육 3장 2절)
애자일과 애자일 테스트 소개 (테스트기본교육 3장 2절)애자일과 애자일 테스트 소개 (테스트기본교육 3장 2절)
애자일과 애자일 테스트 소개 (테스트기본교육 3장 2절)
 
메이븐 기본 이해
메이븐 기본 이해메이븐 기본 이해
메이븐 기본 이해
 
Refactoring tutorial
Refactoring tutorialRefactoring tutorial
Refactoring tutorial
 

More from 진화 손

C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf
진화 손
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf
진화 손
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions
진화 손
 
C++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdfC++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdf
진화 손
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types
진화 손
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements
진화 손
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library
진화 손
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules
진화 손
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules
진화 손
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)
진화 손
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers
진화 손
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]
진화 손
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts
진화 손
 
C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>
진화 손
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr
진화 손
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields
진화 손
 

More from 진화 손 (20)

C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf
 
C++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templatesC++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templates
 
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions
 
C++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdfC++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdf
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts
 
C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields
 

디자인패턴