Design_Pattern - 8BitsCoding/RobotMentor GitHub Wiki

Solid Design Principles


Gamma Categorization

Creational Patterns

  • Deal with the creation (construction) of objects
  • Builder Pattern - 1
  • Builder Pattern - 2 : ์žฌ ์ •๋ฆฌ
    • ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ์‹œ ํ•„์š”ํ•œ ์ƒ์„ฑ์˜ ๋‹จ๊ณ„๋ฅผ ์ž๋…€ํด๋ž˜์Šค์—๊ฒŒ ๋„˜๊ธฐ๋Š” ํ˜•ํƒœ
    • Some objects are simple and can be created in a single constructor call
    • When piecewise(์กฐ๊ฐ์กฐ๊ฐ) object contruction is complicated provice an API for doing it succinctly(๊ฐ„๊ฒฐํ•˜๊ฒŒ)
  • Abstract Factory Pattern
  • (Abstract) Factory Pattern - 2 : ์žฌ ์ •๋ฆฌ
    • ๊ด€๋ จ์žˆ๋Š” ๊ฐ์ฒด์˜ ์ƒ์„ฑ์„ ๊ฐ€์ƒํ™” ํ•œ๋‹ค.
    • A component(๊ตฌ์„ฑ ์š”์†Œ) responsible(์ฑ…์ž„) solely(๋‹ค๋งŒ) for the wholesale(๋ชจ์กฐ๋ฆฌ)(not piecewise) creation of objects.
    • ์—ฌ๊ธฐ์„œ Builder์™€ ์ฐจ์ด์ ์ด Factory์˜ ๊ฒฝ์šฐ wholesale์ด๊ณ  Builder๋Š” piecewise์ด๋ผ๋Š” ์ .
  • Prototype Pattern
  • Prototype Pattern - 2 : ์žฌ ์ •๋ฆฌ
    • ์ƒ์‚ฐ ๋น„์šฉ(๋ฉ”๋ชจ๋ฆฌ)๊ฐ€ ๋†’์€ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ณต์‚ฌ ๋ฐฉ๋ฒ•
    • When it's easier to copy an existing object to fully initialize a new one.
    • Complicated object(e.g. cars) aren't designed from scratch(๊ฐ–์ถ”์–ด์ง„)
    • We make a copy(clone) the prototype and customize it
    • A partially or fully initialized object that you copy(clone) and make use of.
  • SingleTon Pattern
  • SingleTon Pattern - 2 : ์žฌ ์ •๋ฆฌ
    • ๋‹จ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‹ถ์„ ๋•Œ
    • For some components it only makes sense(์ดํ•ดํ•˜๋‹ค) to have one in the system.
    • Want to prevent anyone creating additional copies

Structural Patterns

  • Concerned with the structure (e.g. class members)
  • Many patterns are wrappers that mimic the underlying class' interface
  • Adapter Pattern
  • Adapter Pattern 2 -> ๋ฏธ์ •๋ฆฌ
    • ํŠน์ • ๊ฐ์ฒด์— ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์„ ๋•Œ
    • Getting the interface you want from the interface you have. (๋ง ๊ทธ๋Œ€๋กœ ์ „๊ธฐ ์–ด๋ށํ„ฐ ์ƒ๊ฐํ•˜๋ฉด๋œ๋‹ค. ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ˆ˜์ •ํ•ด์ค€๋‹ค.)
  • Bridge Pattern
  • Bridge Pattern 2
  • ์˜ค๋ธŒ์ ํŠธ ํ•จ์ˆ˜์˜ ๊ตฌํ˜„๋ถ€์™€ ์‚ฌ์šฉ๋ถ€๋ฅผ ๋‚˜๋ˆ„์–ด ์“ฐ๊ณ ์‹ถ์„ ๋•Œ
  • Connecting components together through abstractions.
  • A mechanism that decouples(๋ถ„๋ฆฌ) an interface(hierarchy) from an implementation.
  • Composite Pattern
  • Composite(ํ•ฉ์„ฑ๋ฌผ) Pattern 2 : ๊ฒฐ๊ตญ์€ ๊ฐœ๊ฐœ๋ณ„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํ•˜๋‚˜์˜ ์˜ค๋ธŒ์ ํŠธ๋กœ ๋ฌถ์„ ๋ฐฉ์•ˆ์„ ๊ณ ์•ˆํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.
  • Treating(์น˜๋ฃŒ) individual and aggregate(๊ณจ์žฌ) object uniformly(๊ท ์ผํ•˜๊ฒŒ).
  • Objects use other objects' fields/properties/members through inheritance and composition
  • Composition lets us make compound(ํ™”ํ•ฉ๋ฌผ) objects
  • Composite design pattern is used to treat both single(scalar) and composite objects uniformly

Behavioral Patterns

  • They are all different; no central theme
  • ๋™์ ์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•˜๋ฉฐ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ์‹œ ์‚ฌ์šฉํ•œ๋‹ค.
  • Adding behavior without altering(๋ณ€๊ฒฝ) the class itself.
  • Do not want to rewrite or alter existing code
  • ํŒจํ„ด์ด๋ผ ํ•˜๊ธฐ ํž˜๋“ฆ, ์ผ๋ฐ˜์ ์œผ๋กœ OOPํ˜•ํƒœ์ด๋‹ค.
  • Exposing several components through a single interface
  • ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ  ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๋Š” ํŒจํ„ด ๋งŽ์ด ์‚ฌ์šฉ๋จ.
  • ๊ฒฐ๊ตญ์€ map๊ณผ ๊ฐ™์€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด์„œ ๋ฐ์ดํ„ฐ ๊ด€๋ฆฌํ•˜๋Š” ํŒจํ„ด์ด๋‹ค.
  • Space optimization
  • Avoid redundancy when storing data.
  • A space optimization technique that lets us use less memory by storing externally the data associated with similar objects
  • ๋Œ€๋ฆฌ์ž๋กœ์จ ์ผ์„ ๋งก๊ธฐ๋ฉด ๊ทธ ์ผ์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ์™„๋ฃŒ๋˜๋ฉด ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ์•Œ๋ ค์ฃผ๋Š” ํŒจํ„ด
  • An interface for accessing a particular resource.
  • You are calling foo.bar() -> This assumes that foo is in the same process as bar() -> What if, later on, you want to put all Foo-related operations into a separate process
  • Can you avoid changing yout code? -> Proxy to the rescue!
  • ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ๋ฅผ ์ฒด์ธ์ฒ˜๋Ÿผ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•˜๋ฉฐ ๋ถ€์—ฌ
  • Sequence of handlers processing an event one after another
  • ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ฐ์ฒด์˜ ํ˜•ํƒœ๋กœ ์บก์Аํ™”ํ•˜๋Š” ๋ชฉ์ ์˜ ํŒจํ„ด
  • ๊ฐ์ฒด์˜ ์ถ”์ƒ์  ์ ‘๊ทผ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ  ๋งŒ๋“  ์ถ”์ƒ์  ๊ฐ์ฒด๋ฅผ ๋ฐ”๊ฟ”๊ฐ€๋ฉด์„œ ์“ฐ๊ณ  ์‹ถ์„ ๋•Œ
  • System behavior partially specified at runtime.
  • ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๊ตฌ์กฐ๋ฅผ ์ •์˜ ํ•˜๊ณ  ์ •์˜ํ•œ ์ž๋…€ ํด๋ž˜์Šค์—์„œ ๊ตฌํ˜„ํ•˜๋Š” ์ผ๋ฐ˜์  ํ˜•ํƒœ
  • A high-level blueprint for an algorithm to be completed by inheritors.
  • ์ผ์ข…์˜ Parser๋ผ ์ƒ๊ฐํ•ด๋„ ์ข‹๋‹ค.
  • ๊ฐ€์žฅํšจ์œจ์ ์ธ Parser๋งŒ๋“ค๊ธฐ ๊ฐ•์ขŒ!
  • ์ปจํ…Œ์ด๋„ˆ์˜ Iterator๋ฅผ ์–ด๋–ป๊ฒŒ ๋งŒ๋“œ๋Š”์ง€์— ๊ด€ํ•œ ๋‚ด์šฉ.
  • How traversal of data structores happens and who makes it happen.
  • object์˜ ์ƒํƒœ๋ฅผ undoํ•˜๊ฒŒ ํ•ด์ค€๋‹ค.

A

  • Adapter Pattern : ํŠน์ • ๊ฐ์ฒด์— ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์„ ๋•Œ
  • Abstract Factory Pattern : ๊ด€๋ จ์žˆ๋Š” ๊ฐ์ฒด์˜ ์ƒ์„ฑ์„ ๊ฐ€์ƒํ™” ํ•œ๋‹ค.

B

  • Builder Pattern : ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ์‹œ ํ•„์š”ํ•œ ์ƒ์„ฑ์˜ ๋‹จ๊ณ„๋ฅผ ์ž๋…€ํด๋ž˜์Šค์—๊ฒŒ ๋„˜๊ธฐ๋Š” ํ˜•ํƒœ
  • Bridge Pattern : ์˜ค๋ธŒ์ ํŠธ ํ•จ์ˆ˜์˜ ๊ตฌํ˜„๋ถ€์™€ ์‚ฌ์šฉ๋ถ€๋ฅผ ๋‚˜๋ˆ„์–ด ์“ฐ๊ณ ์‹ถ์„ ๋•Œ

C

  • Composite Pattern
  • Chain of Responsibility Pattern : ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ๋ฅผ ์ฒด์ธ์ฒ˜๋Ÿผ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•˜๋ฉฐ ๋ถ€์—ฌ
  • Command Pattern : ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ฐ์ฒด์˜ ํ˜•ํƒœ๋กœ ์บก์Аํ™”ํ•˜๋Š” ๋ชฉ์ ์˜ ํŒจํ„ด

D

  • Decorator Pattern : ๋™์ ์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•˜๋ฉฐ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ์‹œ ์‚ฌ์šฉํ•œ๋‹ค.

F

  • Facade Pattern : ํŒจํ„ด์ด๋ผ ํ•˜๊ธฐ ํž˜๋“ฆ, ์ผ๋ฐ˜์ ์œผ๋กœ OOPํ˜•ํƒœ์ด๋‹ค.
  • Flyweight Pattern : ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ  ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๋Š” ํŒจํ„ด ๋งŽ์ด ์‚ฌ์šฉ๋จ.

M

  • Mediator Pattern
  • Memeto Pattern : ๊ฐ์ฒด์˜ ์ƒํƒœ ์ •๋ณด๋ฅผ ์ €์žฅ ๋ฐ ๋ณต์›ํ•˜๋Š” ํŒจํ„ด

O

  • Observer Pattern : ๋“ฑ๋ก๋œ ๊ฐ ๊ฐ์ฒด๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‚˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ธŒ๋กœ๋“œ ์บ์ŠคํŠธํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.

P

  • Prototype Pattern : ์ƒ์‚ฐ ๋น„์šฉ(๋ฉ”๋ชจ๋ฆฌ)๊ฐ€ ๋†’์€ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ณต์‚ฌ ๋ฐฉ๋ฒ•
  • Proxy Pattern : ๋Œ€๋ฆฌ์ž๋กœ์จ ์ผ์„ ๋งก๊ธฐ๋ฉด ๊ทธ ์ผ์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ์™„๋ฃŒ๋˜๋ฉด ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ์•Œ๋ ค์ฃผ๋Š” ํŒจํ„ด

S

  • SingleTon Pattern : ๋‹จ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‹ถ์„ ๋•Œ
  • Strategy Pattern : ๊ฐ์ฒด์˜ ์ถ”์ƒ์  ์ ‘๊ทผ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ  ๋งŒ๋“  ์ถ”์ƒ์  ๊ฐ์ฒด๋ฅผ ๋ฐ”๊ฟ”๊ฐ€๋ฉด์„œ ์“ฐ๊ณ  ์‹ถ์„ ๋•Œ
  • State Pattern : ๋™์ ์œผ๋กœ ํ–‰๋™(์•Œ๊ณ ๋ฆฌ์ฆ˜)์„ ๊ต์ฒดํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

T

  • Template Method Pattern : ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๊ตฌ์กฐ๋ฅผ ์ •์˜ ํ•˜๊ณ  ์ •์˜ํ•œ ์ž๋…€ ํด๋ž˜์Šค์—์„œ ๊ตฌํ˜„ํ•˜๋Š” ์ผ๋ฐ˜์  ํ˜•ํƒœ

V

  • Visitor Pattern : ํŠน์ • ๊ฐ์ฒด์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ์˜ค๋ธŒ์ ํŠธ์˜ ๋ฐ์ดํ„ฐ์— ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋ฐ”๊ฟ”๊ฐ€๋ฉฐ ์ ‘๊ทผํ•˜๊ณ  ์‹ถ์„ ๋•Œ