๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŽ iOS/Architecture

[Architecture] VIPER ํŒจํ„ด

์•ˆ๋…•ํ•˜์„ธ์š”, ์ œ์ธ์ž…๋‹ˆ๋‹ค!

์ตœ๊ทผ ์‹œ์ž‘ํ•œ ์•„ํ‚คํ…์ฒ˜ ๋ฐ ๋””์ž์ธ ์Šคํ„ฐ๋””์—์„œ ์ฒซ๋ฒˆ์งธ๋กœ ์ฃผ์ œ๋กœ ๋‹ค๋ฃจ์—ˆ๋˜ VIPER ์•„ํ‚คํ…์ฒ˜ ํŒจํ„ด์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค.

๋ฐ”๋กœ ์‹œ์ž‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค๐Ÿ˜Š

VIPER Pattern์ด๋ž€?

View, Interactor, Presenter, Entity, Router์˜ ์•ฝ์ž๋ฅผ ๋”ฐ์™€์„œ VIPER๋ผ๋Š” ์ด๋ฆ„์ด ๋ช…๋ช…๋œ ๋‹จ์ผ์ฑ…์ž„์›์น™ ๊ธฐ๋ฐ˜์˜ ์•„ํ‚คํ…์ณ์ž…๋‹ˆ๋‹ค. ์‘์ง‘๋„๋Š” ๋†’๊ณ  ๊ฒฐํ•ฉ๋„๋Š” ๋‚ฎ์€ ํ˜•ํƒœ๋กœ, ์•„๋ฌด๋ž˜๋„ ๊ฐ๊ฐ์˜ ๊ตฌ๋ถ„์ด ๋งŽ์€ ๋งŒํผ ์—ญํ•  ๋‹จ์œ„์˜ ๊ตฌ๋ถ„์ด ๋ช…ํ™•ํ•ฉ๋‹ˆ๋‹ค. (์ด๊ฒƒ์ด ๋ญ”๊ฐ€ ์žฅ์ ์ด ๋  ์ˆ˜๋„ ๋‹จ์ ์ด ๋  ์ˆ˜๋„ ์žˆ๋Š” ๊ฒƒ ๊ฐ™๊ธดํ•ฉ๋‹ˆ๋‹ค..)

 

VIPER ํŒจํ„ด

์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๊ทธ๋ฆผ์œผ๋กœ ํ‘œํ˜„ํ•ด๋ดค๋Š”๋ฐ์š”, ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ด…์‹œ๋‹ค!

 

  • View : ์–ด๋–ค ํŒจํ„ด์ด๋“  ์‚ฌ์šฉํ•˜๋Š” View ์—ญํ• ์ž…๋‹ˆ๋‹ค. ์ฃผ๋กœ UIViewController, UIView๋“ค์ด ์ด ์—ญํ• ์„ ํ•˜๊ฒŒ๋ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์— ๋ฐ˜์‘ํ•˜๊ณ  ๋ณด์—ฌ์ฃผ๋Š” ์—ญํ• ์„ ํ•˜๋ฉฐ, ์ฃผ๋กœ Presenter์™€ ์ƒํ˜ธ์ž‘์šฉํ•ฉ๋‹ˆ๋‹ค.
  • Presenter : UI ๊ด€๋ จ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. View์˜ ์•ก์…˜์„ ๋ฐ›์•„์„œ Interactor๋กœ ์ „๋‹ฌํ•˜๊ณ  Interactor๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌ๋ฐ›์•„ View์„ Updateํ•˜๋Š” ๋กœ์ง์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
  • Interactor : ๋ฐ์ดํ„ฐ ๋˜๋Š” ๋„คํŠธ์›Œํฌ์™€ ๊ด€๋ จ๋œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋‹จ์œ„์ž…๋‹ˆ๋‹ค. ์ฃผ๋กœ API ํ˜ธ์ถœ, data ๊ด€๋ จ๋œ ๋กœ์ง์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋‹จ์œ„์˜ ๋ชจ๋“ˆ์ž…๋‹ˆ๋‹ค. (๋ทฐ์™€๋Š” ์™„์ „ ๋…๋ฆฝ์ ์ธ ์—ญํ• ์„ ํ•˜๋Š” ๋ชจ๋“ˆ)
  • Entity : ์ผ๋ฐ˜์ ์ธ ๋ฐ์ดํ„ฐ ๊ฐ์ฒด๋“ค์ž…๋‹ˆ๋‹ค. ๋‹จ์ˆœํ•˜๊ฒŒ, ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • Router : ํ™”๋ฉด์ด ์–ธ์ œ ํ‘œ์‹œ๋˜์–ด์•ผํ•˜๋Š”์ง€ ์–ด๋–ค ํ™”๋ฉด์„ ๋„์šธ์ง€ ๋“ฑ Navigatoin ๋กœ์ง์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. (๋ทฐ ์ „ํ™˜ ๋‹ด๋‹น)

 

๊ธฐ์กด MV* ํŒจํ„ด๊ณผ์˜ ์ฐจ์ด์ 

ํ‘œ๋ฉด์ ์œผ๋กœ ๋ณด์ด๋Š” ์ฐจ์ด์ ์€ Interactor, Entity, Router๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค!

๊ธฐ์กด์˜ ๊ธฐ๋Šฅ์ด ๋” ์ชผ๊ฐœ์ ธ ๋ถ„๋ฆฌ๋˜์—ˆ๋‹ค๋Š” ๊ฒƒ์ธ๋ฐ์š”, ๋ฌด์—‡์ด ๋‚˜๋‰˜์–ด์กŒ์„๊นŒ์š”??๐Ÿค”

 

  • ๊ธฐ์กด MV* ํŒจํ„ด์—์„œ ๋ฐ์ดํ„ฐ ์ƒํ˜ธ์ž‘์šฉ ๋กœ์ง์„ ๋‹ด๋‹นํ–ˆ๋˜ Model์˜ ๊ธฐ๋Šฅ์ด VIPER์—์„œ๋Š” Interactor(๋น„์ง€๋‹ˆ์Šค ๋กœ์ง ๋‹ด๋‹น)์™€ Entities(๋ฐ์ดํ„ฐ ๋ชจ๋ธ)๋กœ ๋‚˜๋‰˜์–ด์กŒ์Šต๋‹ˆ๋‹ค.
  • Router์— ์˜ํ•ด ํ’€๋ฆฌ๋„๋ก ๋˜์–ด์žˆ๋Š” ์ฃผ์†Œ ๋„ค๋น„๊ฒŒ์ด์…˜ ์ฑ…์ž„์„ ๋ช…์‹œ์ ์œผ๋กœ ๋‹ค๋ฃจ๋Š” ์ฒซ๋ฒˆ์งธ ํŒจํ„ด์ด VIPER์ž…๋‹ˆ๋‹ค. ๊ธฐ์กด MV* ํŒจํ„ด์—์„œ๋Š” ์ ์ ˆํ•œ ๋ผ์šฐํŒ…(ํ™”๋ฉด ์ „ํ™˜) ๋ฐฉ์‹์— ๋Œ€ํ•œ ์ด์Šˆ๋ฅผ ๋‹ค๋ฃจ์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
  • Presenter์˜ ์—ญํ• ๋„ ๊ธฐ์กด๊ณผ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. MVP์—์„œ๋Š” Presenter๊ฐ€ ๋ชจ๋“  ๋กœ์ง์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ๋‹ด๋‹นํ•˜์˜€์Šต๋‹ˆ๋‹ค. View์—์„œ ์š”์ฒญํ•œ ์ •๋ณด(UI, ๋ฐ์ดํ„ฐ๊ด€๋ จ ๋ชจ๋‘) ๋ฅผ Model๋กœ๋ถ€ํ„ฐ ๊ฐ€๊ณตํ•˜์—ฌ View๋กœ ๋‹ค์‹œ ์ „๋‹ฌํ•˜์˜€๋Š”๋ฐ, VIPER์—์„œ๋Š” UI์— ๊ด€๋ จ๋œ ์ฒ˜๋ฆฌ๋งŒ์„ ๋งก์Šต๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ ๋˜๋Š” ๋„คํŠธ์›Œํฌ์— ๊ด€ํ•œ ์ฒ˜๋ฆฌ๋Š” Interactor๊ฐ€ ๋‹ด๋‹นํ•ฉ๋‹ˆ๋‹ค.

VIPER์˜ ์žฅ์ ๊ณผ ๋‹จ์ 

์ข‹์€ ์•„ํ‚คํ…์ฒ˜์˜ 3๊ฐ€์ง€ ํŠน์ง•์ธ Distribution, Testability, Easy of use๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ VIPER์˜ ์žฅ์ ๊ณผ ๋‹จ์ ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

 

  • Distribution - ๊ฐ๊ฐ์˜ ์—ญํ•  ๊ตฌ๋ถ„์ด ์ •๋ง ๋ช…ํ™•ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ฑ…์ž„ ๋ถ„๋ฐฐ ๋ฉด์—์„œ๋Š” ์ •๋ง ํฐ ์žฅ์ ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
  • Testability - ์ฑ…์ž„ ๋ถ„๋ฐฐ์˜ ๋ช…ํ™•์„ฑ(๋…๋ฆฝ์„ฑ)์€ ๋” ์ข‹์€ testability๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
  • Easy of Use - ์œ„์—์„œ๋„ ์–ธ๊ธ‰ํ–ˆ๋“ฏ, ์—ญํ•  ๋‹จ์œ„์˜ ๊ตฌ๋ถ„์ด ๋ช…ํ™•ํ•œ ๊ฒƒ์ด ์žฅ์ ์ด์ž ๋‹จ์ ์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ์š”, ๋งค์šฐ ์ž‘์€ ์—ญํ• ์„ ๊ฐ€์ง€๋Š” ํด๋ž˜์Šค๋“ค์„ ์œ„ํ•ด ์—„์ฒญ๋‚˜๊ฒŒ ๋งŽ์€ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ž‘์„ฑํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋งŽ์€ ์œ ์ง€๋ณด์ˆ˜ ๋น„์šฉ์ด ๋“ ๋‹ค๋Š” ๊ฒƒ์ด ๋‹จ์ ์ž…๋‹ˆ๋‹ค.

 

์Šคํ„ฐ๋””์›๋“ค๊ณผ ํ•จ๊ป˜ ์˜ˆ์‹œ ์ฝ”๋“œ๋„ ๋ณด๋ฉฐ VIPER์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐ๋ฅผ ๋‚˜๋ˆˆ ๊ฒฐ๊ณผ..

VIPER..๋Œ€์ฒด ์™œ ์“ฐ๋Š”๊ฑฐ์ง€..? ๋ผ๋Š” ์ด์•ผ๊ธฐ๊ฐ€ ๋‚˜์˜ฌ ์ •๋„๋กœ ์žฅ์ ๋ณด๋‹ค ๋‹จ์ ์ด ๋” ๋งŽ์€ ํŒจํ„ด์ด๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋Š”๋ฐ์š” (ํŠนํžˆ ์œ ์ง€๋ณด์ˆ˜ ๋ฉด์—์„œ)

๋‹ค์Œ ํฌ์ŠคํŒ…์—์„œ VIPER์˜ ๋‹จ์ ์„ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด ๋“ฑ์žฅํ•œ RIBs์— ๋Œ€ํ•ด ํ•œ๋ฒˆ ์ •๋ฆฌํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

๊ธด ๊ธ€ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜Š


[์ฐธ๊ณ ์ž๋ฃŒ]

 

iOS Architecture Patterns

Demystifying MVC, MVP, MVVM and VIPER

medium.com

 

[Design Pattern] VIPER Pattern - iOS Architecture

iOS์˜ Design Pattern์—๋Š” ๋งŽ์€ ๊ฒƒ๋“ค์ด ์žˆ์ฃ ...? MVC, MVVM, VIPER, RIBs, MVP๋“ฑ์ด ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์—ฌ๊ธฐ์„œ ์‚ฌ์šฉํ•ด๋ณธ ๊ฒƒ์€ MVC, MVVM ์ •๋„์ž…๋‹ˆ๋‹ค.. ์•„์ง ์ฐธ ๊ฐˆ๊ธธ์ด ๋จผ ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ˜ข ์˜ค๋Š˜์€ ์ด ์ค‘์—

dongminyoon.tistory.com

 

[Swift] VIPER ํŒจํ„ด์„ ์‚ฌ์šฉํ•œ GitHub Search ๋งŒ๋“ค๊ธฐ 1

์•ˆ๋…•ํ•˜์„ธ์š”! ์˜ค๋Š˜์€ VIPER ํŒจํ„ด(์•„ํ‚คํ…์ฒ˜)์„ ์‚ฌ์šฉํ•ด์„œ ์˜ˆ์ œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณผ๊ฑฐ์—์š”. VIPER ํŒจํ„ด์ด ๋ญ”์ง€ ์•Œ์•„๋ณธ ํ›„์— ๊ตฌํ˜„๋ฐฉ๋ฒ•์„ ์ฝ”๋“œ์™€ ํ•จ๊ป˜ ์„ค๋ช…๋“œ๋ฆฌ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•ด๋ณผ๊ฒŒ์šฉ ํ•œ๋ฒˆ์— ๋‹ค์“ฐ๋ฉด

apple-apeach.tistory.com

'๐ŸŽ iOS > Architecture' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[iOS/Architecture] UseCase ํ™œ์šฉ๊ธฐ  (0) 2024.08.28
[Architecture] Clean Architecture  (1) 2024.01.03
[Architecture] MVC, MVP, MVVM ์•„ํ‚คํ…์ฒ˜ ํŒจํ„ด  (2) 2022.03.25