๐Ÿ—บ๏ธ Design Pattern

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Template Method Pattern - ํ…œํ”Œ๋ฆฟ ๋ฉ”์†Œ๋“œ ํŒจํ„ด

Templete Method Patternํ…œํ”Œ๋ฆฟ ๋ฉ”์†Œ๋“œ ํŒจํ„ด(Template Method Pattern)์€ ์ƒ์œ„ ํด๋ž˜์Šค์—์„œ ๊ธฐ๋ณธ์ ์ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๊ตฌ์กฐ๋ฅผ ์ •์˜ํ•˜๊ณ , ํ•˜์œ„ ํด๋ž˜์Šค์—์„œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํŠน์ • ๋‹จ๊ณ„๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋””์ž์ธ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.์ด ํŒจํ„ด์„ ํ†ตํ•ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๊ตฌ์กฐ๋Š” ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ , ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํŠน์ • ๋‹จ๊ณ„๋ฅผ ์žฌ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ…œํ”Œ๋ฆฟ์ด๋ž€, ์‚ฌ์ „์  ์˜๋ฏธ๋กœ๋Š” ํ˜•ํŒ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.๋ฌธ์ž, ๋„ํ˜•์œผ๋กœ ๊ตฌ๋ฉ์ด ๋šซ๋ ค ์žˆ๋Š” ์–‡์€ ํ”Œ๋ผ์Šคํ‹ฑ ํŒ์„ ์ƒ๊ฐํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์‹ค์ œ๋กœ ์–ด๋–ค ๋„ํ˜•์ด ๊ทธ๋ ค์งˆ์ง€๋Š” ํ•„๊ธฐ๊ตฌ์— ์˜ํ•ด ๊ฒฐ์ •๋ฉ๋‹ˆ๋‹ค.ํŽœ์œผ๋กœ ๊ทธ๋ฆฌ๋ฉด ํŽœ์œผ๋กœ ๊ทธ๋ฆฐ ๋„ํ˜•์ด ๋˜๊ณ , ์—ฐํ•„๋กœ ๊ทธ๋ฆฌ๋ฉด ์—ฐํ•„๋กœ ๊ทธ๋ฆฐ ๋„ํ˜•์ด ๋ฉ๋‹ˆ๋‹ค. Template Method ํŒจํ„ด์€ ํ…œํ”Œ๋ฆฟ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง„ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.์ƒ์œ„ ํด๋ž˜์Šค ์ชฝ์— ํ…œํ”Œ๋ฆฟ ๋ฉ”์„œ๋“œ๊ฐ€ ์ •์˜๋˜์–ด ์žˆ๊ณ , ๊ทธ ๋ฉ”์„œ๋“œ ..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] State Pattern - ์ƒํƒœ ํŒจํ„ด

State Pattern์ƒํƒœ ํŒจํ„ด(State Pattern)์€ ๊ฐ์ฒด๊ฐ€ ๋‚ด๋ถ€ ์ƒํƒœ์— ๋”ฐ๋ผ ํ–‰๋™์„ ๋‹ค๋ฅด๊ฒŒ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๋””์ž์ธ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.๊ฐ์ฒด๋Š” ์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝํ•จ์œผ๋กœ์จ ํ–‰๋™์ด ๋ฐ”๋€๋‹ˆ๋‹ค.์ƒํƒœ ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜๋ฉด ์กฐ๊ฑด๋ฌธ์„ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ณ  ํ™•์žฅ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.State๋Š” ์ƒํƒœ = ์‚ฌ๋ฌผ์˜ ๋ชจ์–‘์ด๋‚˜ ํ˜•ํŽธ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.๋˜ํ•œ ์ƒํƒœ๋ฅผ ํด๋ž˜์Šค๋กœ ํ‘œํ˜„ํ•˜๋ฉด ํด๋ž˜์Šค๋ฅผ ๊ต์ฒดํ•ด์„œ '์ƒํƒœ์˜ ๋ณ€ํ™”'๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.Strategy Pattern๊ณผ ์กฐ๊ธˆ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค.  ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“ค๊ณ ์ž ํ•˜๋Š” Object์— ์ƒํƒœ๊ฐ€ ์žˆ๋‹ค๋ฉด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” Pattern ์ž…๋‹ˆ๋‹ค. ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๋Š” ๊ฐ€์žฅ ๋Œ€ํ‘œ์ ์ธ ์˜ˆ๊ฐ€ ์‹ ํ˜ธ๋“ฑ ์ž…๋‹ˆ๋‹ค.๋…น์ƒ‰, ๋นจ๊ฐ•์ƒ‰ ์ค‘ ํ•˜๋‚˜์˜ ์ƒํƒœ๋งŒ ๊ฐ€์ง€๋Š” ๊ธฐ๊ณ„์ด๋ฉฐ, ๊ณ„์†ํ•ด์„œ ์ƒํƒœ๊ฐ€ ๋ณ€ํ™”๋ฉ๋‹ˆ๋‹ค.State Pattern์„ ์‚ฌ..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Mediator Pattern - ๋งค๋””์—์ดํ„ฐ ํŒจํ„ด

Mediator PatternMediator ํŒจํ„ด์€ ๊ฐ์ฒด์ง€ํ–ฅ ์„ค๊ณ„์—์„œ ๊ฐ์ฒด๋“ค ๊ฐ„์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ์ค‘์žฌํ•˜๋Š” ์ค‘์žฌ์ž(Mediator) ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ฒด๋“ค์ด ์ง์ ‘์ ์œผ๋กœ ์„œ๋กœ ์ฐธ์กฐํ•˜์ง€ ์•Š๊ณ  ํ†ต์‹ ํ•˜๋„๋ก ๋งŒ๋“œ๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค.์ด๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด๋“ค ๊ฐ„์˜ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถ”๊ณ , ์ƒํ˜ธ์ž‘์šฉ์„ ํ•œ ๊ณณ์— ์ง‘์ค‘์‹œ์ผœ์„œ ์ฝ”๋“œ์˜ ์œ ์ง€๋ณด์ˆ˜์„ฑ์„ ๋†’์ž…๋‹ˆ๋‹ค.๋˜ํ•œ ๊ฐ์ฒด๊ฐ„์˜ ๋ณต์žกํ•œ ์ƒํ˜ธ์ž‘์šฉ์„ ์ค‘์•™ ์ง‘์ค‘ํ™”ํ•˜์—ฌ ๊ด€๋ฆฌํ•  ํ•„์š”๊ฐ€ ์žˆ๋Š” ์ƒํ™ฉ์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.์ด๋ฅผ ํ†ตํ•ด์„œ ๊ฐ์ฒด๋“ค์ด ์ง์ ‘ ํ†ต์‹ ํ•˜๋Š” ๋Œ€์‹  Mediator๋ฅผ ํ†ตํ•ด ๊ฐ„์ ‘์ ์œผ๋กœ ํ†ต์‹ ํ•˜๋„๋ก ํ•˜์—ฌ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถ”๊ณ  ์ฝ”๋“œ์˜ ์œ ์ง€ ๋ณด์ˆ˜์„ฑ์„ ๋†’์ž…๋‹ˆ๋‹ค. Mediator๋Š” ์ค‘๊ฐœ์ธ, ๊ฐ ํšŒ์›๋“ค์€ colleage ์ž…๋‹ˆ๋‹ค.Diagram of Mediator PatternMediator๋Š” ์ค‘๊ฐœ์ธ, ๊ฐ ํšŒ์›๋“ค์€ colleage ์ž…..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Visitor Pattern - ๋ฐฉ๋ฌธ์ž ํŒจํ„ด

Visitor PatternVisitor Pattern์€ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ์™€ ์ฒ˜๋ฆฌ๋ฅผ ๋ถ„๋ฆฌํ•˜๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค.๋ฐ์ดํ„ฐ ๊ตฌ์กฐ ์•ˆ์— ๋งŽ์€ ์š”์†Œ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๊ณ , ๊ทธ ๊ฐ ์š”์†Œ์— ๋ฐํ•˜์—ฌ ๋ฌด์—‡์ธ๊ฐ€ ์ฒ˜๋ฆฌํ•ด ๋‚˜๊ฐ„๋‹ค๊ณ  ํ• ๋•Œ, ์ด๋•Œ ๊ทธ ์ฒ˜๋ฆฌ์˜ ์ฝ”๋“œ๋Š” ์–ด๋””์— ์จ์•ผ ํ• ์ง€ ๊ณ ๋ฏผ์ด ๋ฉ๋‹ˆ๋‹ค.์ผ๋ฐ˜์ ์œผ๋กœ ์ƒ๊ฐํ•˜๋ฉด ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋ฅผ ํ‘œ์‹œํ•˜๊ณ  ์žˆ๋Š” ํด๋ž˜์Šค ์•ˆ์— ๊ธฐ์ˆ  ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.ํ•˜์ง€๋งŒ, ๋งŒ์•ฝ ๊ทธ ์ฒ˜๋ฆฌ๊ฐ€ ์—ฌ๋Ÿฌ ์ข…๋ฅ˜๋ผ๋ฉด ์ƒˆ๋กœ์šด ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•  ๋•Œ๋งˆ๋‹ค ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ์˜ ํด๋ž˜์Šค๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.์š”์†Œ๋“ค์˜ ํด๋ž˜์Šค๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ์ƒˆ๋กœ์šด ์ž‘์—…์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๋””์ž์ธ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.๊ฐ์ฒด ๊ตฌ์กฐ๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ ๋„ ์ƒˆ๋กœ์šด ์ž‘์—…์„ ์‰ฝ๊ฒŒ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.Visitor ํŒจํ„ด์€ ๊ฐ์ฒด์˜ ๊ตฌ์กฐ๊ฐ€ ์•ˆ์ •์ ์ด์ง€๋งŒ ๊ฐ์ฒด์— ์ˆ˜ํ–‰ํ•  ์ž‘์—…์€ ์ž์ฃผ ๋ฐ”๋€Œ๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๋ฉด ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.๊ฐ..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Observer Pattern - ์˜ต์ €๋ฒ„ ํŒจํ„ด

Observer PatternObserver๋Š” ๊ด€์ฐฐํ•˜๋Š” ์‚ฌ๋žŒ์˜ ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.Observer ํŒจํ„ด์—์„œ๋Š” ๊ด€์ฐฐ ๋Œ€์ƒ(Subject)์˜ ์ƒํƒœ๊ฐ€ ๋ณ€ํ™”ํ•˜๋ฉด ๊ด€์ฐฐ์ž(Observer)์—๊ฒŒ ์•Œ๋ ค์ค๋‹ˆ๋‹ค.Obsever ํŒจํ„ด์€ ์ƒํƒœ ๋ณ€ํ™”์— ๋”ฐ๋ฅธ ์ฒ˜๋ฆฌ๋ฅผ ๊ธฐ์ˆ ํ•  ๋•Œ ํšจ๊ณผ์ ์ž…๋‹ˆ๋‹ค.์–ด๋– ํ•œ ์ด๋ฒคํŠธ๊ฐ€ ์ผ์–ด๋‚ฌ์„ ๋•Œ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ”๋ผ๋ณด๋˜ ๊ฐ์‹œ์ž๋“ค์ด ๋ฐ”๋กœ ๋ฐ˜์‘ํ•  ์ˆ˜ ์žˆ๋Š” Pattern ์ž…๋‹ˆ๋‹ค.-> Subscriber, Listener Pattern Observer Pattern์ด ์•„๋‹Œ ๊ฒฝ์šฐ์ด๋ฒคํŠธ๊ฐ€ ์ผ์–ด๋‚ฌ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด 1์ดˆ, 1๋ถ„, 1์‹œ๊ฐ„๋งˆ๋‹ค ํ™•์ธ์„ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.์ด๋Ÿฌํ•œ ๋ฐฉ๋ฒ•์„ polling ์ด๋ผ๊ณ  ํ•˜์—ฌ ํ•„์š” ์—†๋Š” ๋ฆฌ์†Œ์Šค ๋‚ญ๋น„๊ฐ€ ์ƒ๊น๋‹ˆ๋‹ค.Polling ์ฃผ๊ธฐ๊ฐ€ 1์‹œ๊ฐ„์ผ ๊ฒฝ์šฐ, 1์‹œ๊ฐ„ ์ด๋‚ด์— ์ด๋ฒคํŠธ ์ผ์–ด๋‚˜๋‹ค๊ฐ€ ์‚ฌ๋ผ์ง„๋‹ค๋ฉด ์ด๋ฒคํŠธ๊ฐ€ ์ผ์–ด๋‚ฌ๋Š”์ง€ ์•Œ ์ˆ˜ ..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Memento Pattern - ๋ฉ”๋ฉ˜ํ†  ํŒจํ„ด

Memento PatternMemento ํŒจํ„ด์€ ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ณต์›ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๋””์ž์ธ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.์ด ํŒจํ„ด์€ ๊ฐ์ฒด์˜ ๋‚ด๋ถ€ ์ƒํƒœ๋ฅผ ์บก์Šํ™”ํ•˜์—ฌ ์™ธ๋ถ€์— ๋…ธ์ถœ์‹œํ‚ค์ง€ ์•Š๊ณ ๋„ ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ณต์›ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.์ผ๋ฐ˜์ ์œผ๋กœ ์–ด๋–ค Object์˜ ํžˆ์Šคํ† ๋ฆฌ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์œ ์šฉํ•œ ํŒจํ„ด์ž…๋‹ˆ๋‹ค. → ๊ฒŒ์ž„์—์„œ Saveํ•˜๋Š” ๊ฒƒ์„ ๋– ์˜ฌ๋ฆฌ๋ฉด ๋ฉ๋‹ˆ๋‹ค.๊ฐ€๋ น ํ…์ŠคํŠธ ์—๋””ํ„ฐ ์‚ฌ์šฉํ•  ๋•Œ undo์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ญ์ œ ํ•˜๊ธฐ ์ „ ์ƒํƒœ๋กœ ํ…์ŠคํŠธ ๋ณต์›์ด ๊ฐ€๋Šฅํ•˜๊ณ , ๊ทธ ๊ธฐ๋Šฅ์„ ๋ช‡ ๋‹จ๊ณ„๋กœ ์‹คํ–‰ํ•ด์„œ ํŽธ์ง‘์ž‘์—…์„ ์ ์  ๊ณผ๊ฑฐ๋กœ ๋Œ๋ฆฌ๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•จ๊ฐ์ฒด์ง€ํ–ฅํ”„๋กœ๊ทธ๋žจ์—์„œ undo๊ธฐ๋Šฅ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ •๋ณด๋ฅผ ์ €์žฅํ•ด ๋‘˜ ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.๋‹จ, ์ €์žฅ๋งŒ ํ•ด์„œ๋Š” ์•ˆ๋˜๊ณ , ์ €์žฅํ•œ ์ •๋ณด๋กœ๋ถ€ํ„ฐ ์ธ์Šคํ„ด์Šค๋ฅผ ์›๋Œ€๋ž˜๋กœ ๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Chain of Responsibility

Chain of Responsibility PatternChain of Responsibility Pattern์€ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ๋ฅผ ์—ฌ๋Ÿฌ ๊ฐ์ฒด๋“ค์—๊ฒŒ ๋ถ€์—ฌํ•จ์œผ๋กœ์จ ๊ทธ๋“ค ๊ฐ„์˜ ๊ฒฐํ•ฉ๋„๋ฅผ ์—†์• ์ฃผ๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค.๋ณต์ˆ˜์˜ Object๋ฅผ ์‚ฌ์Šฌ์ฒ˜๋Ÿผ ์—ฐ๊ฒฐํ•ด์ฃผ๋ฉด, ๊ทธ ์˜ค๋ธŒ์ ํŠธ์˜ ์‚ฌ์Šฌ์„ ์ฐจ๋ ˆ๋Œ€๋กœ ๋Œ์•„๋‹ค๋‹ˆ๋ฉด์„œ ๋ชฉ์ ํ•œ Object๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.responsibility ๊ฐœ๋…์„ ๊ฐ–๋Š” ๋ชจ๋“ˆ๋“ค์— ์ฒด์ธ์„ ๋งŒ๋“œ๋Š” Pattern ์ž…๋‹ˆ๋‹ค.chain of responsibility pattern์ด ์•„๋‹Œ ๊ฒฐ์ œ ์˜ˆ์ œํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ์—์„œ ๊ฒฐ์ œ ์š”์ฒญ์„ ๋ฐœํ–‰ ํ•ฉ๋‹ˆ๋‹ค.๊ฒฐ์ œ ์š”์ฒญ ์•ˆ์—๋Š” ๊ฒฐ์ œ๋ฐฉ๋ฒ•๊ณผ ๊ธˆ์•ก์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.๊ฒฐ์ œ ๋ฐฉ๋ฒ•์—๋Š” cash, credit card, debit card ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.๊ฒฐ์ œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜๋‚˜ ํด๋ž˜์Šค๊ฐ€ ์žˆ์–ด..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Command Pattern - ์ปค๋งจ๋“œ ํŒจํ„ด

Command Pattern์ปค๋งจ๋“œ ํŒจํ„ด์€ ์š”์ฒญ์„ ๋…๋ฆฝ๋œ ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์š”์ฒญ์— ๋Œ€ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ํฌํ•จํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ํ–‰๋™ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.๋‹ค์–‘ํ•œ ์š”์ฒญ์„ ๋ฉ”์„œ๋“œ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜ํ™”ํ•˜๊ณ , ์š”์ฒญ์˜ ์‹คํ–‰์„ ์ง€์—ฐํ•˜๊ฑฐ๋‚˜ ํ์— ๋„ฃ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์‹คํ–‰ ์ทจ์†Œ ๊ธฐ๋Šฅ์„ ์ง€์›ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์—ฌ๋Ÿฌ ๋ช…๋ น๋“ค์„ ์ถ”์ƒํ™”ํ•ด์„œ class๋กœ ์ •์˜ํ•˜๊ณ  Object๋กœ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•˜๋Š” Pattern์ž…๋‹ˆ๋‹ค.๋˜ํ•œ ํ–‰์œ„(Behavior) ํŒจํ„ด์— ์†ํ•ฉ๋‹ˆ๋‹ค.ํด๋ž˜์Šค๊ฐ€ ์ผ์„ ์‹คํ–‰ํ• ๋–„, ์ž์‹ ์˜ ํด๋ž˜์Šค or ๋‹ค๋ฅธ ํด๋ž˜์Šค์˜ Method๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.๊ทธ๋Ÿฌ๋‚˜ Method๋ฅผ ํ˜ธ์ถœํ•œ ๊ฒฐ๊ณผ๋Š” Object์— ๋ฐ˜์˜๋˜์ง€๋งŒ, ์ผ์˜ ์ด๋ ฅ์€ ์–ด๋””์—๋„ ๋‚จ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.์ด๋•Œ, ‘์ด ์ผ์„ ์‹คํ–‰ํ•˜์‹œ์˜ค’ ๋ผ๋Š” ‘๋ช…๋ น’์„ ํ‘œํ˜„ํ•˜๋Š” ํด๋ž˜์Šค๊ฐ€ ์žˆ์œผ๋ฉด ํŽธํ•ฉ๋‹ˆ๋‹ค.๋ช…๋ น์„ ๋‚˜ํƒ€๋‚ด๋Š” ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋กœ ํ•˜๋‚˜์˜ ‘๋ฌผ๊ฑด’์ฒ˜..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Strategy Pattern - ์ „๋žต ํŒจํ„ด

Strategy Pattern์ŠคํŠธ๋ž˜ํ‹ฐ์ง€ ํŒจํ„ด(Strategy Pattern)์€ ํ–‰์œ„ ํŒจํ„ด(Behavioral Pattern)์˜ ์ผ์ข…์œผ๋กœ, ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฐ์„ ์ •์˜ํ•˜๊ณ , ๊ฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์บก์Šํ™”ํ•˜๋ฉฐ, ์ด๋“ค์„ ์ƒํ˜ธ ๊ตํ™˜ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค.์ฆ‰, ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ํด๋ผ์ด์–ธํŠธ์—์„œ ๋ถ„๋ฆฌํ•˜์—ฌ ๋…๋ฆฝ์ ์œผ๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.์ด๋ฅผ ํ†ตํ•ด ํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ์˜ ๋ณ€๊ฒฝ ์—†์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‰ฝ๊ฒŒ ๊ต์ฒดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.Runtime ์ค‘์— ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์„ ํƒํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.ํ•˜๋‚˜์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ง์ ‘ Implementing ํ•˜๋Š” ๋Œ€์‹  ์–ด๋– ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ• ์ง€ Runtime Instruction์„ ๋ฐ›์Šต๋‹ˆ๋‹ค.Animal์„ ๋ฐ›์•„์„œ Speaking์„ ์‹œํ‚ค๋Š” ํ•จ์ˆ˜๋™๋ฌผ์€ ๊ณ ์–‘์ด ํ˜น์€ ์‚ฌ์ž๊ณ ์–‘์ด๊ฐ€ ๋“ค์–ด์˜ค๋ฉด “meow”์‚ฌ์ž๊ฐ€ ๋“ค์–ด์˜ค๋ฉด “roar”ํ•จ์ˆ˜๋Š” ์ด ์ƒํƒœ๋กœ ๊ณ ์ •์ด..

๐Ÿ—บ๏ธ Design Pattern

[Design Pattern] Composite Pattern - ์ปดํฌ์ง€ํŠธ ํŒจํ„ด

Composite Pattern์ปดํฌ์ง€ํŠธ ํŒจํ„ด(Composite Pattern)์€ ๊ฐ์ฒด๋ฅผ ํŠธ๋ฆฌ ๊ตฌ์กฐ๋กœ ๊ตฌ์„ฑํ•˜์—ฌ ๋ถ€๋ถ„-์ „์ฒด ๊ณ„์ธต์„ ๊ตฌํ˜„ํ•˜๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค.์ด๋ฅผ ํ†ตํ•ด ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋‹จ์ผ ๊ฐ์ฒด์™€ ๋ณตํ•ฉ ๊ฐ์ฒด๋ฅผ ๋™์ผํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์ปดํฌ์ง€ํŠธ ํŒจํ„ด์€ ๊ตฌ์กฐ ํŒจํ„ด(Structural Pattern)์˜ ์ผ์ข…์œผ๋กœ, ๊ฐ์ฒด๋ฅผ ๊ทธ๋ฃน์œผ๋กœ ๋ฌถ์–ด ํ•˜๋‚˜์˜ ๊ฐ์ฒด์ฒ˜๋Ÿผ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.์ปดํ“จํ„ฐ์˜ ํŒŒ์ผ ์‹œ์Šคํ…œ์—์„œ๋Š” Directory ๋ผ๋Š” ๊ฒƒ์ด ์žˆ๊ณ , Directory์•ˆ์—๋Š” ํŒŒ์ผ์ด๋‚˜ ๋‹ค๋ฅธ ํ•˜์œ„ Directory๊ฐ€ ์žˆ๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.๋งˆ์น˜ “์ƒ์ž ์•ˆ์˜ ์ƒ์ž” ๊ฐ™์€ ๊ตฌ์กฐ, ์ฆ‰ ์žฌ๊ท€์  ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.Directory ์—”ํŠธ๋ฆฌ๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ์กฐ์‚ฌํ•  ๋•Œ, ๊ทธ๋ฆ‡๊ณผ ๋‚ด์šฉ๋ฌผ์„ ๊ฐ™์€ ์ข…๋ฅ˜๋กœ ์ทจ๊ธ‰ํ•˜๋ฉด ํŽธ๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์ด ๊ทธ๋ฆ‡์„ ๋‚ด์šฉ๋ฌผ๊ณผ ๋™์ผ์‹œ ํ•˜์—ฌ ์žฌ๊ท€์ ์ธ ๊ตฌ์กฐ..

Bigbread1129
'๐Ÿ—บ๏ธ Design Pattern' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก