CH02 Clean Architecture 4 Layer

κ°•μ˜μ—μ„œ λ‹€λ£¨λŠ” 4 Layer λ‚΄μš©

κ°•μ˜μ—μ„œ ν”„λ‘œμ νŠΈλ₯Ό κ΅¬ν˜„ν•  λ•Œ κ·Όκ°„μœΌλ‘œ μ‚¬μš©ν•˜λŠ” 섀계ꡬ쑰인 4개의 계측이닀. 그리고 κ°•μ˜μ—μ„œ μ‚¬μš©λ˜λŠ” μ„œλ“œνŒŒν‹° λΌμ΄λΈŒλŸ¬λ¦¬λ“€μ— λŒ€ν•œ μ•ˆλ‚΄μ΄λ‹€.

개인적으둜 μ°Ύμ•„ λ³Έ Flutter 클린 μ•„ν‚€ν…μ²˜ Layer

κ°•μ˜μžλ£Œλ§Œ λ΄μ„œλŠ” μ •ν™•νžˆ 이해가 κ°€μ§€ μ•Šμ•„μ„œ μ•„λž˜ μ„Έ κ°€μ§€ ν¬μŠ€νŒ…μ„ μ°Έκ³  ν–ˆλ‹€.

μœ„μ˜ 각각의 ν¬μŠ€νŒ…μ—μ„œ 닀루고 μžˆλŠ” Layer ꡬ뢄듀을 도식화 ν•œ 이미지듀은 μ•„λž˜μ™€ κ°™λ‹€.

ν¬μŠ€νŒ…λ§ˆλ‹€ μ•½κ°„μ”© μ‚¬μš©λ˜λŠ” μš©μ–΄κ°€ λ‹€λ₯Έ 뢀뢄이 있긴 ν–ˆλŠ”λ° κ³΅ν†΅μ μœΌλ‘œ κ²°κ΅­ 같은 이야기λ₯Ό ν•˜κ³  μžˆλ‹€.

일단 κ°œμΈμ μœΌλ‘œλŠ” μ„Έ ν¬μŠ€νŒ… 쀑 Flutter x Clean Architecture κ°€ κ°€μž₯ λ³΄κΈ°μ—λŠ” μ’‹μ•˜λ˜ 것 κ°™λ‹€. λ„ˆλ¬΄ μžμ„Ένžˆ λ˜λŠ” λ„ˆλ¬΄ λ‹¨μˆœνžˆ λ¬˜μ‚¬ν•˜μ§€ μ•ŠμœΌλ©΄μ„œλ„ μ •ν™•ν•˜κ²Œ 각 Layer 의 μ—­ν• κ³Ό 각 Layer 에 μ†ν•˜λŠ” κ²ƒλ“€μ˜ 역할듀을 μ„€λͺ…ν•˜κ³  μžˆμ–΄μ„œλ‹€.

각 κ°œλ…μ— λŒ€ν•΄μ„œ λ‚˜μ˜ 말둜 ν’€μ–΄μ„œ λ‹€μ‹œ 정리λ₯Ό ν•΄λ³΄μž.

Layer μ •μ˜

일단 Layer λ“€μ˜ ꡬ뢄에 λŒ€ν•΄μ„œ μ•Œμ•„λ³΄κΈ° 전에 Layer μžμ²΄μ— λŒ€ν•œ μ •μ˜λ₯Ό ν•΄μ•Όν•œλ‹€. ν¬μŠ€νŒ…μ— 이미 정리가 잘 λ˜μ–΄ μžˆλŠ”λ° λ‹¨μˆœν•˜κ²Œ ν‘œν˜„ν•˜μžλ©΄ Layer λŠ” Architecture λ₯Ό κ΅¬μ„±ν•˜λŠ” κ°œλ…μ΄λ‹€. λ…λ¦½λ˜μ–΄ μžˆμœΌλ©΄μ„œ Architecture 의 ꡬ성에 ν¬ν•¨λ˜κΈ° μœ„ν•΄μ„œ νŠΉμ •ν•œ μ±…μž„μ„ μ§€λŠ” κ°œλ…μ μΈ ꡬ뢄 계측이닀.

Architecture Let’s start with the basics: what is app architecture? App architecture is the logical way we organize our projects and how the various components interact with each other to fulfill the business requirements. We want to follow standards and make it easy to identify the components that we’ll need to develop features in our codebase. The way we establish the relationship and interactions between these components can reduce or add complexity to our projects, which has a significant impact on the team’s productivity.

Layers Now that we know what architecture is, let’s define layers. Layers are the components that compose your architecture. We can define these by assigning a specific responsibility to them. We should keep these layers simple, yet isolated enough to achieve a maintainable codebase.

각 Layer(Presentation Layer, Domain Layer, Data Layer) 탐ꡬ 및 Layer ꡬ성 μ—­ν•  이해

각 ꡬ성에 κ΄€ν•΄μ„œκΉŒμ§€ μ„Έμ„Έν•˜κ²Œ 도식화가 된 것은 μ•„λž˜ 그림이 κ°€μž₯ μ’‹μ•˜λ‹€.

Flutter x Clean Architecture 이 ν¬μŠ€νŒ…μ— λ‚˜μ˜¨ 그림인데 μ•„μ‰¬μš΄ 점은 Layer 자체만 μ„€λͺ…ν–ˆμœΌλ©΄ μ’‹κ² λŠ”λ° 일뢀 κ°œλ…μ΄ Bloc 에 μ˜μ‘΄μ μ΄λ‹€.

각 Layer λ₯Ό νŒ¨ν‚€μ§€λ‘œ μ•Œμ•„λ³΄κΈ°

기쑴에 λ‹€λ₯Έ λ ˆνΌλŸ°μŠ€μ—μ„œ μ•Œμ•„λ΄€λ˜ μžλ£Œλ“€κ³Ό λΉ„κ΅ν–ˆμ„λ•Œ Application Layer 뢀뢄이 쑰금 λ‹€λ₯΄λ‹€. 일단 κ°•μ˜μ—μ„œλŠ” μ €λ ‡κ²Œ μ‚¬μš©ν•œλ‹€. κ°•μ˜λ₯Ό λͺ¨λ‘ 끝내면 λ‹€ 듀어가보지 μ•Šμ•„λ„ λͺ¨λ‘ νŒŒμ•…ν•˜κ³  μžˆμ–΄μ•Όν•  λ‚΄μš©μ΄λ‹€

λ‚΄κ°€ μ •λ¦¬ν•œ Layer 별 상세 정리

각 Layer κ°€ μ‹€μ œλ‘œ μ–΄λ–»κ²Œ κ΅¬ν˜„λ˜λŠ”μ§€μ— λŒ€ν•΄μ„œ ν•™μŠ΅ν–ˆλ‹€. μ†ŒμŠ€μ½”λ“œ λ₯Ό μ²¨λΆ€ν•œλ‹€.

ν•™μŠ΅ν•œ 것을 기반으둜 μ•„λž˜ 그림을 λ§Œλ“€μ—ˆλ‹€. 각 ꡬ성과 μ„ΈλΆ€ ν•­λͺ©μ„ λ‚΄μž¬ν™” ν•˜μž. 참고둜 κ°•μ˜μ—μ„œ κ·œμ •ν•œ Application Layer λŠ” μ•„λž˜ κ·Έλ¦Όμ—μ„œ μƒλž΅ν–ˆλ‹€.

Application Layer λŠ” λ‹€λ₯Έ Layer λ“€κ³Ό μƒν˜Έμž‘μš© ν•œλ‹€κΈ° λ³΄λ‹€λŠ” μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜ 전역에 μ μš©λ˜λŠ” μžμ›μ— λŒ€ν•œ Layer 이닀. λ°±μ—”λ“œμ—μ„œ μ‚¬μš©ν–ˆλ˜ AppConfig νŒ¨ν‚€μ§€μ™€ μ“°μž„κ³Ό 역할이 μ™„μ „νžˆ μΌμΉ˜ν•œλ‹€.

μ—¬κΈ°μ„œ UI Widget κ³Ό State Management μ‚¬μ΄μ˜ μƒν˜Έ μž‘μš©μ΄ κ³§ view 와 viewModel κ°„μ˜ μƒν˜Έμž‘μš©μ΄λ©° λ³΅μŠ΅μ„ μœ„ν•΄ μ•„λž˜ 그림을 λ‹€μ‹œ 보자.

κ΅¬ν˜„ ν•˜λ‹€κ°€ μž κΉμ”© λ§‰νžˆλ”λΌλ„ ν•™μŠ΅ν–ˆλ˜ 것을 보고 κ΅¬ν˜„μ„ ν•˜λ©΄ κ·Έλ§Œμ΄λ‹€. 달달 μ™Έμš°λŠ”κ²Œ μ€‘μš”ν•œ 것이 μ•„λ‹ˆκ³  μ €λ ‡κ²Œ 계측을 λ‚˜λˆ„λŠ” μ΄μœ μ— λŒ€ν•΄μ„œ μ•Œκ³ , 계측을 λ‚˜λˆ„λŠ” κ³Όμ •μ—μ„œ μ–΄λ–€ λ°©μ‹μœΌλ‘œ μ²˜λ¦¬ν–ˆλŠ”μ§€μ™€ κ·Έ κ³Όμ •μ—μ„œ μ–΄λ–€ 라이브러리λ₯Ό μ‚¬μš©ν–ˆλŠ”μ§€ 등에 λŒ€ν•΄μ„œ μΈμ§€ν•˜μž.

κ°•μ˜μ—μ„œλŠ” μ—λŸ¬ μ½”λ“œμ— λŒ€ν•΄μ„œ 더 잘 μ²˜λ¦¬ν•΄ λ‘μ—ˆλŠ”λ°, λ‚˜μ˜ ν”„λ‘œμ νŠΈμ—μ„œλŠ” λ‹€λ₯΄κ²Œ μ²˜λ¦¬ν•  κ°€λŠ₯성이 μ»€μ„œ μ‹€μŠ΅μ—μ„œλŠ” μƒλž΅ν–ˆλ‹€.

Last updated