๐Ÿ› Android์˜ Clean Architecture์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž !

sery270ยท2021๋…„ 5์›” 5์ผ
24

Android

๋ชฉ๋ก ๋ณด๊ธฐ
10/13
post-thumbnail

์˜ค๋Š˜์€ ์ œ๊ฐ€ Android ๊ฐœ๋ฐœ์ž๋กœ ํ™œ๋™ํ•˜๋Š” MARU์™€ ๊ด€๋ จ๋œ ์ฃผ์ œ๋ฅผ ๊ฐ€์ง€๊ณ  ์™”์Šต๋‹ˆ๋‹ค! MARU์˜ Android ๊ฐœ๋ฐœ์ž๋“ค์€ Clean Architecture๋ฅผ ์ง€ํ–ฅํ•˜๋ฉฐ ์—ด์‹ฌํžˆ ๊ฐœ๋ฐœํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”, ์˜ค๋Š˜์€ ์ด Clean Architecture๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์•Œ์•„๋ณด๊ณ , MARU๊ฐ€ ์ด๋ฅผ ์–ด๋–ป๊ฒŒ ์†Œํ™”ํ•˜๊ณ  ์žˆ๋Š”์ง€ ์†Œ๊ฐœํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์‹ค ์ตœ๊ทผ๊นŒ์ง€ Clean Architecture์— ๋Œ€ํ•ด์„œ ์ž˜ ๋ชฐ๋ž์—ˆ๋Š”๋ฐ, MARU๋ผ๋Š” ์ข‹์€ ๊ธฐํšŒ๋กœ Clean Architecture๋ฅผ ๊ณต๋ถ€ํ•˜๊ณ  ๊ฒฝํ—˜ํ•  ๊ธฐํšŒ๊ฐ€ ์ƒ๊ฒจ ๊ธฐ์ฉ๋‹ˆ๋‹ค. ์šฉ์–ด๊ฐ€ ๋‹ค์–‘ํ•˜๊ณ , ์ถ”์ƒ์ ์ธ ๊ฐœ๋…๋“ค์„ ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ค์› ์ง€๋งŒ, ์ตœ๋Œ€ํ•œ ๊ณต์‹ ๋ ฅ ์žˆ๋Š” ์ž๋ฃŒ๋ฅผ ๋ณด๊ณ  ์†Œํ™”ํ•˜๋ ค ๋…ธ๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค ! ๊ธ€์— ๋Œ€ํ•œ ํ”ผ๋“œ๋ฐฑ ํ•ญ์ƒ ํ™˜์˜์ž…๋‹ˆ๋‹ค :) ๊ทธ๋Ÿผ ์˜ค๋Š˜๋„ ํ™”์ดํŒ…์ž…๋‹ˆ๋‹ค ๐ŸŒฟ

1๏ธโƒฃ Clean Architecture๊ฐ€ ๋ฌด์—‡์ผ๊นŒ


๊ฐœ๋ฐœ์ž๋“ค ์‚ฌ์ด์—์„œ, ๊ณผ๋… ๋ชจ์–‘ ๊ทธ๋ฆผ ์ด๋ผ๋˜๊ฐ€, ์–‘ํŒŒ ๋ชจ์–‘ ๊ตฌ์กฐ๋„๋ผ๋Š” ํ‘œํ˜„์„ ์“ฐ๊ณคํ•˜๋Š”๋ฐ์š”. ๋ฐ”๋กœ Robert C. Martin (Uncle Bob)์˜ Clean Architecture ๊ทธ๋ฆผ์„ ์ง€์นญํ•˜๋Š” ๋ง์ž…๋‹ˆ๋‹ค ๐Ÿคช

Clean Architecture์˜ ์ „๋ถ€๋ฅผ ์•„๋ž˜ ๊ทธ๋ฆผ์ด ํ‘œํ˜„ํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์™œ Clean Architecture๋ฅผ ์‚ฌ์šฉํ• ๊นŒ ?

  • Clean Architecture์˜ ์ฐฝ์‹œ์ž์ธ Robert C. Martin (Uncle Bob)๊ฐ€ ์šด์˜ํ•˜๋Š” The Clean Code Blog์— ์˜ํ•˜๋ฉด, Clean Architecture๊ฐ€ ์‹œ์Šคํ…œ์— ์ฃผ๋Š” ์ด์ ์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ํ•œ ๋ฌธํ•ญ์”ฉ ํ•ด์„ํ•ด๊ฐ€๋ฉฐ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
  1. Independent of Frameworks. The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints.
  2. Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.
  3. Independent of UI. The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.
  4. Independent of Database. You can swap out Oracle or SQL Server, for Mongo, BigTable, CouchDB, or something else. Your business rules are not bound to the database.
  5. Independent of any external agency. In fact your business rules simply donโ€™t know anything at all about the outside world.
  1. Clean Architecture๋Š” ํ”„๋ ˆ์ž„ ์›Œํฌ์— ๋…๋ฆฝ์ ์ž…๋‹ˆ๋‹ค.
    • Clean Architecture๋Š” ์ผ๋ถ€ ๊ธฐ๋Šฅ์ด ํฌํ•จ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ (๊ณง ํ”„๋ ˆ์ž„์›Œํฌ)์— ์˜์กดํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    • ์ด๋ฅผ ํ†ตํ•ด ํ”„๋ ˆ์ž„์›Œํฌ์˜ ์ œ์•ฝ์— ์‹œ์Šคํ…œ์„ ๋งž์ถ”๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ์‹œ์Šคํ…œ์˜ ๋„๊ตฌ๋กœ์จ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.
  2. Clean Architecture๋Š” ํ…Œ์ŠคํŠธ๋ฅผ ์šฉ์ดํ•˜๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.
    • The business rules(Entity)๋ฅผ ํ…Œ์ŠคํŠธํ•˜๋Š”๋ฐ์— ์™ธ๋ถ€ ์š”์†Œ๋ฅผ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  3. Clean Architecture๋Š” UI์— ๋…๋ฆฝ์ ์ž…๋‹ˆ๋‹ค.
    • ๋‹ค๋ฅธ ์‹œ์Šคํ…œ ๋ณ€๊ฒฝ ์—†์ด, UI๋ฅผ ์‰ฝ๊ฒŒ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (UI ๋ณ€๊ฒฝ์˜ ์šฉ์ด์„ฑ์„ ์ค๋‹ˆ๋‹ค.)
      • ์˜ˆ๋“ค ๋“ค๋ฉด, ์›น UI์—์„œ Console UI๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค ํ• ๋•Œ, The business rules(Entity)๋ฅผ ๋ณ€๊ฒฝ์—†์ด ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  4. Clean Architecture๋Š” DB์™€ ๋…๋ฆฝ์ ์ž…๋‹ˆ๋‹ค.
    • The business rules(Entity)์ด DB์— ๋ฐ”์ธ๋”ฉ ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ, DB์˜ ์ข…๋ฅ˜๋ฅผ ์‰ฝ๊ฒŒ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
      • ์˜ˆ๋ฅผ ๋“ค๋ฉด, Oracle์—์„œ SQL Server, for Mongo, BigTable, CouchDB ๋“ฑ๋“ฑ์œผ๋กœ ์‰ฝ๊ฒŒ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  5. Clean Architecture๋Š” ์™ธ๋ถ€์™€ ๋…๋ฆฝ์ ์ž…๋‹ˆ๋‹ค.
    • The business rules(Entity)๋Š” ์™ธ๋ถ€์— ๋Œ€ํ•ด ์•Œํ•„์š”๊ฐ€ ์—†๊ณ , ์ „ํ˜€ ์•Œ์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค.
      • ์ด ๋•๋ถ„์— 1-4์˜ ์ด์ ์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Dependency Rule

  • (์œ„ ๊ทธ๋ฆผ ์ถœ์ฒ˜) ์œ„ ๊ทธ๋ฆผ์—์„œ ์˜์กด์„ฑ ๋ฒ•์น™์€ Entites๋กœ ํ–ฅํ•˜๋Š” ํ™”์‚ดํ‘œ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, ํ•ญ์ƒ ์›์˜ ์•ˆ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ์˜์กด์„ฑ์ด ์กด์žฌํ•ด์•ผํ•˜๊ณ , ๋ฐ”๊นฅ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ์˜ ์˜์กด์„ฑ์€ ์กด์žฌํ•˜์ง€ ์•Š์•„์•ผํ•œ๋‹ค๋Š” ์˜๋ฏธ๋กœ ํ•ด์„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    • ๊ทธ๋ฆผ์— ๋”ฐ๋ฅด๋ฉด, ๋ฐ”๊นฅ ์ชฝ์˜ ์š”์†Œ A๋Š” ์•ˆ์ชฝ์˜ ์š”์†Œ B๋ฅผ ํ•„์š”๋กœ ํ•ฉ๋‹ˆ๋‹ค.

      "A๊ฐ€ B๋ฅผ ํ•„์š”๋กœ ํ•œ๋‹ค." ๋ผ๋Š” ์˜์กด ๊ด€๊ณ„๋ฅผ UML ์˜ ํ‘œํ˜„์„ ๋นŒ๋ ค, A - - -> B๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    • ๊ทธ๋ ‡๋‹ค๋ฉด ๊ณผ์—ฐ, ์•ˆ์ชฝ์˜ ์š”์†Œ B๋Š” ๋ฐ”๊นฅ ์ชฝ์˜ ์š”์†Œ A๋ฅผ ์ ˆ๋Œ€ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š์„๊นŒ์š”?

      • ์•„๋ž˜์—์„œ repository ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜๋ฉฐ, ๋‹ค์‹œ ์–ธ๊ธ‰ํ•˜๊ฒ ์ง€๋งŒ, ๊ทธ๋ ‡์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ ์ด B๊ฐ€ ์˜์กด ๊ด€๊ณ„๋ฅผ ํšŒํ”ผํ•˜์—ฌ A๋ฅผ ์‚ฌ์šฉํ•  ๋ฟ์ž…๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ ์˜์กด์„ฑ ์—ญ์ „ ๋ฒ•์น™๊ณผ ํ•จ๊ป˜ ๋‹ค์‹œ ๋ง์”€๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.
  • ์˜์กด์˜ ๋ฐฉํ–ฅ์€ ๋ณ€๊ฒฝ์˜ ์œ ์—ฐ์„ฑ๊ณผ๋„ ๊ด€๋ จ์ด ์žˆ์Šต๋‹ˆ๋‹ค. Clean Architecture์—์„ , ์˜์กด์˜ ๋ฐฉํ–ฅ์ด ์•ˆ์ชฝ์œผ๋กœ๋งŒ ํ–ฅํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๋ฐ”๊นฅ์ชฝ์— ์žˆ์„์ˆ˜๋ก ๋ณ€ํ•˜๊ธฐ ์‰ฌ์šด, ์•ˆ์ชฝ์— ์žˆ์„์ˆ˜๋ก ๋ณ€ํ•˜๊ธฐ ์–ด๋ ค์šด ์š”์†Œ๋ผ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

2๏ธโƒฃ Clean Architecture์˜ Layer๋“ค


(์•„๋ž˜ ๊ทธ๋ฆผ ์ถœ์ฒ˜) ์•„๋ž˜ ๊ทธ๋ฆผ์€ ์œ„์—์„œ ๋ณด์•˜๋˜ Clean Architecture ๊ทธ๋ฆผ์„ 90๋„ ํšŒ์ „ํ•œ ๋ชจ์Šต์ž…๋‹ˆ๋‹ค. Clean Architecture์˜ ๊ฐ Layer๋“ค์„ ์„ค๋ช…ํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜์™€ ๊ฐ™์ด ํ™œ์šฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Presentation Layer

์œ„ ๊ทธ๋ฆผ์˜ Presenter๋ฅผ Presenters๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ViewModels๋„ ํฌ๊ด„ํ•˜๊ธฐ ์œ„ํ•œ ๋ง๋กœ, Controllers๋ผ ๋ถ€๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.

  • UI (Activities & Fragments), Controllers (Presenters/ViewModels) ๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

  • Controllers (Presenters/ViewModels)์€ 1๊ฐœ ์ด์ƒ์˜ Use cases๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • UI์€ UI ๊ฐ๊ฐ์˜ Controllers (Presenters/ViewModels)์— ์˜ํ•ด ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.

  • Presentation Layer๋Š” Domain Layer์„ ๋Œ€์ƒ์œผ๋กœ ์˜์กด์„ฑ์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

    Presentation Layer - - - > Domain Layer

Domain Layer

  • Entities, Use cases, Repository Interfaces๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

  • Use cases๋Š” data์™€ 1๊ฐœ ์ด์ƒ์˜ Repository Interfaces๋ฅผ ๊ฒฐํ•ฉํ•ฉ๋‹ˆ๋‹ค.

  • Domain Layer๋Š” ๊ฐ€์žฅ ์•ˆ์ชฝ์˜ ๋ ˆ์ด์–ด์ž…๋‹ˆ๋‹ค. ์•ž์„œ ์–ธ๊ธ‰ํ•œ ์˜์กด์„ฑ ๋ฒ•์น™์— ์˜ํ•ด, Domain Layer๋Š” ๋‹ค๋ฅธ ๋ ˆ์ด์–ด๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์˜์กด์„ฑ์„ ๊ฐ€์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋ ˆ์ด์–ด๊ฐ€ Domain Layer๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์˜์กด์„ฑ์„ ๊ฐ€์งˆ ๋ฟ์ž…๋‹ˆ๋‹ค.

    ์–ด๋–ป๊ฒŒ Domain Layer๋Š” Data Layer์— ๋Œ€ํžŒ ์˜์กด์„ฑ๋„ ๊ฐ€์ง€์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‚˜์š”?

    ํ•œ๋งˆ๋””๋กœ ๋‹ต๋ณ€ํ•˜์ž๋ฉด, SOLID ์›์น™ ์ค‘ ์˜์กด์„ฑ ์—ญ์ „ ๋ฒ•์น™์— ํ•ด๋‹นํ•˜๋Š” interface๋ฅผ ์‚ฌ์šฉํ•œ ์ถ”์ƒํ™” ๋•๋ถ„์ž…๋‹ˆ๋‹ค.

    Interface ์ถ”์ƒํ™”๊ฐ€ ์—†์—ˆ๋‹ค๋ฉด, Domain Layer์˜ Use cases๊ฐ€ Data Layer์˜ Repository๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, Domain Layer - - - > Data Layer ๋ผ๋Š” ์˜์กด์ด ์ƒ๊ฒจ๋‚˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

    ํ•˜์ง€๋งŒ Domain Layer๋Š” Repository๋ฅผ ์ถ”์ƒํ™”์‹œ์ผœ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ์œ„์™€ ๊ฐ™์€ ์˜์กด์ด ์ƒ๊ฒจ๋‚˜์ง€ ์•Š๊ฒŒ ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฆ‰, Domain Layer๋Š” Data Layer์—์„œ ๊ตฌํ˜„๋  Repository Interfaces๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ, ์˜์กด์„ ํšŒํ”ผํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

    ์ด๊ฒƒ์ด ๋ฐ”๋กœ Repository Interfaces๊ฐ€ Domain Layer์— ํฌํ•จ๋˜๋Š” ์ด์œ ์ด์ž, Repository Implementations๊ฐ€Data Layer์— ํฌํ•จ๋˜๋Š” ์ด์œ  ๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์˜์กด์„ฑ ์—ญ์ „ ๋ฒ•์น™์„ ํ•œ๋งˆ๋””๋กœ ?

    High-level modules should not depend on low-level modules, both should depend on abstractions.

Domain Layer์˜ ํŠน์ง• โ€ผ๏ธ

  • Domain Layer ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ ˆ์ด์–ด ์ž…๋‹ˆ๋‹ค โ€ผ๏ธ ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ ๋ ˆ์ด์–ด๋“ค๊ณผ๋Š” ๋‹ฌ๋ฆฌ, ์ž˜ ๋ฐ”๋€Œ๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.
    • ์ด Domain Layer์— ์†Œํ”„ํŠธ์›จ์–ด์˜ ์ค‘์‹ฌ์ด ๋˜๋Š” The business rules(Entity)๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.
  • Domain Layer๋Š” ๋‹ค๋ฅธ ๋ ˆ์ด์–ด๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์˜์กด์„ฑ์„ ๊ฐ€์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    • ์ฆ‰, Domain Layer๋Š” ํ”„๋ ˆ์ž„ ์›Œํฌ(Android Platform)์— ์˜์กด์„ฑ์„ ๊ฐ€์ง€์ง€ ์•Š๊ณ , ์˜ค์ง ์–ธ์–ด ๋‹จ(Kotlin Module)์— ๋Œ€ํ•ด์„œ๋งŒ ์˜์กด์„ฑ์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.
      • ๋”ฐ๋ผ์„œ, ํ”„๋ ˆ์ž„ ์›Œํฌ๊ฐ„์˜ Domain Layer ์žฌ์‚ฌ์šฉ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

Data (DataSource) Layer

  • Repository Implementations, 1๊ฐœ ์ด์ƒ์˜ Data Sources๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

    Data Layer์˜ Repository Implementations

    Data Layer๊ฐ€ ๊ฐ€์ง„ ์ฑ…์ž„ ์ค‘ ํ•˜๋‚˜๋กœ, Domain Layer๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” Repository Interfaces์— ๋Œ€ํ•œ ๊ตฌํ˜„์„ ์ด์•ผ๊ธฐ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Domain Layer๋Š” Data Layer๊ฐ€ ๊ตฌํ˜„ํ•ด์ค„๊ฑฐ๋ผ ์ƒ๊ฐํ•˜๊ณ  Repository Interfaces๋ฅผ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

  • Repository๋Š” ๋‹ค๋ฅธ Data Source๋“ค์„ ๊ฒฐํ•ฉ/์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

    • Repository ์—ฌ๋Ÿฌ Data Source๋“ค์„ ๊ฒฐํ•ฉํ•˜๋Š” ๊ฒฝ์šฐ๋กœ, Local Data Source๊ณผ Remote Data Source์˜ ๊ฒฐํ•ฉ์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

      dataSource์™€ dataSourceImpl

      Data Layer์˜ Data Source๋„, ์œ„์—์„œ ๋ดค๋˜ ์˜์กด์„ฑ ์—ญ์ „ ๋ฒ•์น™์˜ ์ ์šฉ์œผ๋กœ, ์ถ”์ƒํ™” ๋˜์–ด interface์™€ Implementations์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.
      ์ฆ‰, Repository - - -> Data Source์˜ ์˜์กด์— ๋Œ€ํ•œ ํšŒํ”ผ์ž…๋‹ˆ๋‹ค.

      ํ•œํŽธ, ์ด๋ ‡๊ฒŒ ์˜์กด์„ ์—†์• ๋ฉด, Data Source์˜ ๋ณ€๊ฒฝ์‹œ, Repository์— ๋Œ€ํ•œ ์˜ํ–ฅ์„ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

      Repository ํŒจํ„ด์„ ํ•œ๋งˆ๋””๋กœ ?

      ๋ฐ์ดํ„ฐ ์ถœ์ฒ˜ (data source)์™€ ๊ด€๊ณ„ ์—†์ด, ๋™์ผํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ํŒจํ„ด์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

      ์˜ˆ๋ฅผ ๋“ค๋ฉด, Repository ํŒจํ„ด์€ Room(๋‚ด๋ถ€์ €์žฅ์†Œ)์œผ๋กœ ๊ด€๋ฆฌ๋˜๋Š” ๋ฐ์ดํ„ฐ์™€ (local data source data) , Retrofit2๋ฅผ ํ†ตํ•ด ๋ฐ›์•„์˜ค๋Š” ๋ฐ์ดํ„ฐ(remote data source data)์˜ ๊ตฌ๋ถ„์„ ์—†์• , ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” Domain Layer๊ฐ€ ๋ฐ์ดํ„ฐ ์ถœ์ฒ˜(data source)๋ฅผ ์•Œ ํ•„์š” ์—†๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.

  • Data Layer๋Š” Domain Layer์„ ๋Œ€์ƒ์œผ๋กœ ์˜์กด์„ฑ์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

    Data Layer - - - > Domain Layer

3๏ธโƒฃ Clean Architecture์˜ Data Flow


์ฝœ๊ณผ ์ŠคํŠธ๋ฆผ ๋ฐฉ์‹์— ๋Œ€ํ•ด ๊ณต๋ถ€ ์ค‘์ž…๋‹ˆ๋‹ค ~,~

#๏ธโƒฃ Reference


profile
๊ฐœ๋ฐœ์„ธ๋ฆฌ์˜ ์„ฑ์žฅ๊ธฐ๐ŸŒฟ

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2021๋…„ 5์›” 18์ผ

์ž˜ ์ฝ๊ณ ๊ฐ‘๋‹ˆ๋‹ค!
Android TV๋ฅผ ํ•˜๊ธฐ ์ „์— ์ด ํฌ์ŠคํŠธ๋ฅผ ๋ดค๋”๋ผ๋ฉด ์ข€ ๋” ์‹ ๊ฒฝ์จ์„œ ํ–ˆ์„ํ…๋ฐ! ใ…‹ใ…‹

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ

์ •๋ง ์ž˜๋ดค์Šต๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ