ݺߣ

ݺߣShare a Scribd company logo
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

Similar to 디자인패턴 (20)

PPTX
Domain Driven Design
hyun soomyung
PPTX
[Dev rookie]designpattern
대영 노
PDF
Create a solution including deep learning models
Tae Young Lee
PDF
HolubOnPatterns/chapter2_2
SeungHyun Hwang
ODP
Design pattern 4
Daniel Lim
PDF
로토이핑
정인 주
PDF
Devon 2011-b-5 효과적인 레거시 코드 다루기
Daum DNA
PPTX
Patterns for effectviely documenting frameworks
Sunuk Park
PDF
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
Hyun-Soo Ji
PPTX
디자인패턴 1~13
Shin heemin
PPTX
Head first디자인패턴 1~13_희민_호준
HoJun Sung
PPTX
Design patterns
Joshua Yoon
PDF
Let'Swift 2023 Swift Macro, 어디다 쓰죠?
williciousk
PPTX
Prototyping
taehee kim
PDF
딥러닝 세계에 입문하기 위반 분투
Ubuntu Korea Community
PDF
검색엔진에 적용된 ChatGPT
Tae Young Lee
PDF
개발자, 성장하는 '척' 말고, 진짜 성장하기
Donghyun Cho
PDF
애자일과 애자일 테스트 소개 (테스트기본교육 3장 2절)
SangIn Choung
PDF
메이븐 기본 이해
중선 곽
PPTX
Refactoring tutorial
Bingu Shim
Domain Driven Design
hyun soomyung
[Dev rookie]designpattern
대영 노
Create a solution including deep learning models
Tae Young Lee
HolubOnPatterns/chapter2_2
SeungHyun Hwang
Design pattern 4
Daniel Lim
로토이핑
정인 주
Devon 2011-b-5 효과적인 레거시 코드 다루기
Daum DNA
Patterns for effectviely documenting frameworks
Sunuk Park
SNU UX Lab 패턴랭귀지 (The origin of Pattern Language)
Hyun-Soo Ji
디자인패턴 1~13
Shin heemin
Head first디자인패턴 1~13_희민_호준
HoJun Sung
Design patterns
Joshua Yoon
Let'Swift 2023 Swift Macro, 어디다 쓰죠?
williciousk
Prototyping
taehee kim
딥러닝 세계에 입문하기 위반 분투
Ubuntu Korea Community
검색엔진에 적용된 ChatGPT
Tae Young Lee
개발자, 성장하는 '척' 말고, 진짜 성장하기
Donghyun Cho
애자일과 애자일 테스트 소개 (테스트기본교육 3장 2절)
SangIn Choung
메이븐 기본 이해
중선 곽
Refactoring tutorial
Bingu Shim

More from 진화 손 (20)

PPTX
[C++ 20] [P1035R7] Input range adaptors.
진화 손
PPTX
[C++ 20] [P0645R10] Text formatting 내용 정리
진화 손
PPTX
C++20 constexpr default constructor of std::atomic and std::atomic_flag
진화 손
PDF
[C++ 20][P0325R4] std::to_array() 내용 정리.
진화 손
PDF
C++ 20 Efficient access to std::basic_stringbuf’s buffer
진화 손
PDF
C++20 Remove std::weak_equality and std::strong_equality.pdf
진화 손
PDF
C++20 std::execution::unseq.pdf
진화 손
PDF
C++ 20 class template argument deduction for alias templates
진화 손
PDF
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
진화 손
PDF
C++ 20 Unevaluated asm-declaration in constexpr functions
진화 손
PDF
C++20 Utility functions to implement uses-allocator construction
진화 손
PDF
C++ 20 std__reference_wrapper for incomplete types
진화 손
PDF
C++ 20 Stronger Unicode requirements
진화 손
PDF
C++20 Concepts library
진화 손
PDF
C++20 Coroutine
진화 손
PDF
C++ 20 Relaxing the range-for loop customization point finding rules
진화 손
PDF
C++ 20 Relaxing the structured bindings customization point finding rules
진화 손
PDF
C++20 explicit(bool)
진화 손
PDF
C++20 std::map::contains
진화 손
PDF
C++20 Comparing unordered containers
진화 손
[C++ 20] [P1035R7] Input range adaptors.
진화 손
[C++ 20] [P0645R10] Text formatting 내용 정리
진화 손
C++20 constexpr default constructor of std::atomic and std::atomic_flag
진화 손
[C++ 20][P0325R4] std::to_array() 내용 정리.
진화 손
C++ 20 Efficient access to std::basic_stringbuf’s buffer
진화 손
C++20 Remove std::weak_equality and std::strong_equality.pdf
진화 손
C++20 std::execution::unseq.pdf
진화 손
C++ 20 class template argument deduction for alias templates
진화 손
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
진화 손
C++ 20 Unevaluated asm-declaration in constexpr functions
진화 손
C++20 Utility functions to implement uses-allocator construction
진화 손
C++ 20 std__reference_wrapper for incomplete types
진화 손
C++ 20 Stronger Unicode requirements
진화 손
C++20 Concepts library
진화 손
C++20 Coroutine
진화 손
C++ 20 Relaxing the range-for loop customization point finding rules
진화 손
C++ 20 Relaxing the structured bindings customization point finding rules
진화 손
C++20 explicit(bool)
진화 손
C++20 std::map::contains
진화 손
C++20 Comparing unordered containers
진화 손
Ad

디자인패턴