์ฝ์ ๊ธฐ์ ๋ธ๋ก๊ทธ ์๋ฌธ + ์ถ์ฒ
https://proandroiddev.com/a-robust-mvi-with-jetpack-compose-e08882d2c4ff
A robust MVI with Jetpack Compose
Implementing an MVI Architecture recognisable to all
proandroiddev.com
์ง๊ทนํ ๊ฐ์ธ ์คํฐ๋๋ฅผ ์ํ ๊ธ
1. Robust ?
๊ธ์ ์๋์ robust architecture ๋ผ๊ณ ๊ฐ์กฐ๋ ๋ถ๋ถ์ ๋ณด์๋ค. ํด๋น ์ฉ์ด๋ฅผ ๊ทธ๋ฅ ์ง๋์น๋ฉด ์๋ ๊ฒ ๊ฐ๋ค.
robust ์ฌ์ ์ ๋ป๋ ๋ณด๊ณ
์ํํธ์จ์ด ๊ด๋ จํด์ ์ด๋ป๊ฒ ์ฐ์ด๋์ง๋ ์ดํด๋ณด์๋ค.
์ํคํผ๋์์์์ ๋ป : Robustness๋ ํ์ธํ๋ค.
์์ Software robustness์ ๊ดํด์ ์ด ๊ธ๋ ์์๋ค.
https://nexwebsites.com/blog/software-robustness/
What is Software Robustness? How to Ensure Quality and Reliability - Nexus Software Systems
Robustness is an essential quality attribute for software systems, because it ensures that they can continue to operate correctly in real-world scenarios and avoid potential safety hazards or loss of critical data.
nexwebsites.com
๐ค ๋ด๊ฐ ์ดํดํ robustํ ์ํํธ์จ์ด๋, ์ฝ๊ฒ ๋งํด ์๋ฌ ์ฒ๋ฆฌ, ํนํ ์ฌ์ฉ์์ ์ ๋ ฅ๊ณผ ๊ด๋ จํ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ์ํ๋ ์ํํธ์จ์ด๋ฅผ ๋งํ๋ ๊ฒ ๊ฐ๋ค. ๋ฌธ์ ์ํฉ์ด ๋ฐ์ํ ์ดํ์๋ ์ฌ์ฉ์๊ฐ ๋ถํธํจ ์์ด ์๋น์ค๋ฅผ ์ด์ฉํ๋๋ก ์ด์์ ๋ํ ๋์์ ์ํ๋ ์ํํธ์จ์ด๋ฅผ ๋งํ๋ ๊ฒ ๊ฐ๋ค. robust๋ ๋จ์ด๋ฅผ ์ด ์ด์ ๊ฐ ์ดํด๊ฐ ๊ฐ๋ค.
robust/robustness ๋ผ๋ ์ฉ์ด ํ๋์ ์ง์คํด์ ์คํฐ๋ํด๋ ๋ ๋ฏ ํ๋ค.
2. ์ ์์ ๊ถ์ฅ ์ฌํญ
๊ธ์ด ๋ณธ๋ก ์ผ๋ก ๋ค์ด๊ฐ๊ธฐ ์ ์ ๋ค์๊ณผ ๊ฐ์ด 4 ๊ฐ์ง๋ฅผ ๊ถ์ฅํ๋ค.
- Recommendation of ViewBinding over DataBinding : DataBinding ๋ณด๋ค๋ ViewBinding ์ฐ๊ธฐ
- Transition from XML to Jetpack Compose : XML์์ Jetpack Compose๋ก ๋ณํํ๊ธฐ
- Appearance of MVI : MVI ํจํด
- Stable release of KMP : ์์ ์ ์ธ ๋ฒ์ ์ KMP
์ ์ด๋ฐ ์ฌํญ๋ค์ ๊ถ์ฅํ๋ ์ง์ ๋ํ ์์ธํ ์ค๋ช ์ ์์ง๋ง, ์ ์๋ ์ ์ ํ์ต ๊ณก์ ๊ณผ ๋ชจ๋ ๊ฐ๋ฐ์๋ค์ด ํ์ ํ ์ ์๋ robust ์ํคํ ์ฒ๋ฅผ ์ํ ์์ ์ ํ๋ ์ฌ๋์ด๋ผ๊ณ ํ๋, ๊ทธ์ ๊ฒฝํ์น๊ฐ ๋ด๊ธด ๊ถ์ฅ ์ฌํญ๋ค์ด๊ฒ ๋ค.
์ ์์ ์๋๋ฅผ ๋ค๋ ์ ์ ์์ง๋ง, ๋์ถฉ ์ด๋ ์ง ์์๊น ์ถ์ ์ด์ ๋ค์ ์ฐพ์๋ณธ๋ค.
1. ์ด์ ๋ถํฐ DataBinding์ ๊ถ์ฅํ์ง ์๋๋ค๋ ๊ฑด ์๊ณ ์์๋ค.
(๋ฒ์ญ) Data Binding์ ์ฌ์ฉํ์ง ๋ง์์ผ ํ๋ ์ด์
์๋ฌธ : https://medium.com/p/cf3c439637c
medium.com
2. Jetpack Compose์ XMl ๊ฐ ๋น๊ต. Jetpack Compose์ ์ฅ์ ๋ค์ ์ง์คํด์ผ ๊ฒ ๋ค.
XML VIEWS OR JETPACK COMPOSE: WHICH IS THE BEST OPTION FOR YOUR NEXT PROJECT?
Photo by Markus Spiske on Unsplash
medium.com
3. ๊ณผ๊ฑฐ ์ ๊ธ์ ํตํด MVI์ ๋ํด์ ์ข ํ์ ํ์๋ค. ๋น์ ๋๋ MVI๋ ์ด์๋ฅผ ๋ง๋ค์ง ์๊ฒ ๋ค๋ ์์ง๋ก ์ฌ์ฉ์ ์ ๋ ฅ์ ๋ํ ํต์ /๊ด๋ฆฌ ๋ํ์์ผ๋ก Intent๊ฐ ๋ฑ์ฅํ ๊ฒ์ด ์๋๊น ์๊ฐํ์๋ค. ์์กด์ฑ์ ๊ณ ๋ คํ ๋ MVI๋ ๋จ๋ฐฉํฅ ๋ฐ์ดํฐ์ ์ปคํ๋ง์ด ์์ด์ ์ํคํ ์ฒ๋ก๋ ๊ด์ฐฎ์ ๊ฑฐ ๊ฐ๋ค.
https://brunch.co.kr/@oemilk/113
MVC, MVP, MVVM, MVI
Android MVC, MVP, MVVM, MVI | MVC, MVP, MVVM, MVI ์๋๋ก์ด๋ ์ฑ์ ๊ฐ๋ฐํ ๋, ์ด์ฉํ ์ ์๋ ์ฌ๋ฌ ์ํคํ ์ฒ ํจํด๋ค์ด ์์ต๋๋ค. MVC (Model-View-Controller) MVP (Model-View-Presenter) MVVM (Model-View-ViewModel) MVI (Model-View-I
brunch.co.kr
4. ์ ์ ์๊ฐ KMP๋ฅผ ๊ถ์ฅํ๋์ง ํ์ ํ ์๊ฐ ์์ง๋ง, ์ผ๋จ KMP๊ฐ ์ข๋ค๋ ๊ธ์ ์ฐพ๋ ๋ดค๋ค. ๋น์ฆ๋์ค ๋ก์ง ๋ฑ ๋ชจ๋ ๊ณต์ ๊ฐ ๋ค์ํ ํ๋ซํผ ๊ฐ ๊ฐ๋ฅํ๋ ๊ฒ์ด ์ํคํ ์ฒ๋ฅผ ์ฌ์ฌ์ฉํ ์ ์๋ค๋ ์ ์ ์ฅ์ ์ธ ๊ฒ ๊ฐ๋ค.
The Unique Advantages of Kotlin Multiplatform Over Other Cross-Platform Solutions
Understanding How KMP Stands Apart
blog.stackademic.com
3. MVI
๊ธ์์ MVI์ ๋ํด ๊ฐ๋ตํ ์ค๋ช ํ๋ค.
MVI๋ Model-View-Intent์ ์ฝ์์ด๋ค.
๊ธฐ๋ณธ ์๋ฆฌ๋ ์ธํ Intent๋ฅผ ๋ฐ์์ ๊ธฐ๋ณธ UI๋ฅผ ํํํ๋ ViewState๋ฅผ ์์ฑํ๋ state machine์ด๋ผ๊ณ ํ๋ค.
MVVM๊ณผ๋ ๋ค๋ฅด๊ฒ SSoT(Single Source of Truth) ์์น์ด ์๋ค๊ณ ํ๋ค.
SSoT ์๋ฏธ์ ๋ํด ์ฐพ์๋ณด๊ธฐ.
https://en.wikipedia.org/wiki/Single_source_of_truth
Single source of truth - Wikipedia
From Wikipedia, the free encyclopedia Information systems good practice for data normalization In information science and information technology, single source of truth (SSOT) architecture, or single point of truth (SPOT) architecture, for information syst
en.wikipedia.org
https://chancethecoder.tistory.com/45
SSOT(Single Source of Truth)๋?
SSOT๋ Single Source of Truth์ ์ฝ์ด๋ก, ๋ฐ์ดํฐ๋ฒ ์ด์ค, ์ ํ๋ฆฌ์ผ์ด์ , ํ๋ก์ธ์ค ๋ฑ์ ๋ชจ๋ ๋ฐ์ดํฐ์ ๋ํด ํ๋์ ์ถ์ฒ๋ฅผ ์ฌ์ฉํ๋ ๊ฐ๋ ์ ์๋ฏธํฉ๋๋ค. ์ด๋ ๋ฐ์ดํฐ์ ์ ํ์ฑ, ์ผ๊ด์ฑ, ์ ๋ขฐ์ฑ์ ๋ณด์ฅํ
chancethecoder.tistory.com
'๋ฐ์ดํฐ ์์ค๋ ํ ๊ตฐ๋ฐ์์๋ง ๊ด๋ฆฌ/ํต์ ํด์ผ์ง ์ฌ๋ฌ๋ชจ๋ก ์ข๋ค'๋๊ฒ SSoT.
MVI ์ฐธ๊ณ
[๋ฒ์ญ] ์๋๋ก์ด๋๋ฅผ ์ํ MVI (Model-View-Intent) ์ํคํ ์ณ ํํ ๋ฆฌ์ผ: ์์ํ๊ธฐ
MVI Architecture for Android Tutorial: Getting Started
jaehochoe.medium.com
4. ํ์ฉ ์์
Jetpack Compose์ MVI๋ฅผ ์ด์ฉํ ์์ ์ฝ๋์ ๋ํ ์ค๋ช ์ด ๋์จ๋ค.
reducer interface๊ฐ ๋ฑ์ฅํ๋ค. ์ด reducer interface๋ UI์ ViewModel๊ฐ์ ๊ณ์ฝ(contract)๋ผ๊ณ ์ค๋ช ํ๋ค. mvi ์์ reducer์ ์ญํ ์ด ์ด์ ์ํ ๊ฐ์์ ์ต์ ์ํ ๊ฐ์ ๋ง๋๋ ๊ฒ์ ๊ณ ๋ คํ ๋ reducer interface๊ฐ ์ด๋ฐ ์ญํ ์ ํ ๊ฒ์ด๋ค.
์ด reducer interface์ ์ธ ๊ฐ์ง object inteface(ViewState, ViewEvent, ViewEffect) ์ reduce ํจ์(์ด์ ์ํ ์ธํ์ผ๋ก ์ต์ ์ํ ์์ํ ๋ฐํ)๊ฐ ์๋ค.
์ธ ๊ฐ์ง object interface๋ฅผ ๋ณด์. ViewState, ViewEvent, ViewEffect ์ ์ธ ๊ฐ์ง๊ฐ ์๋ค.
- ViewState : Compose UI์ ์ํ. ํ๋ฉด์ ์์๋ค์ ์ํ ์ ๋ณด๋ค์ด ๋ด๊ธด๋ค.
- ViewEvent : ์ฌ์ฉ์์ ํ๋ฉด์ ์ํธ์์ฉ (์ํธ์์ฉ ์ด์์ผ ์๋ ์๋ค). ViewModel ์์ ์ํ๋ฅผ ๋ณ๊ฒฝ์ํจ๋ค.
- ViewEffect : ViewEvent์ ์ผ์ข ์ด๋ผ๊ณ ํ๋๋ฐ, ์ด ๋ถ๋ถ์ ์ ์ดํด๊ฐ ๊ฐ์ง ์๋๋ค. ์คํ๋ ค ViewState๊ฐ ์์์ ์ธ UI ์ํ๋ผ๋ฉด, ViewEffect๋ ์ผํ์ฑ/๋จ๋ฐ์ฑ UI ๋์์ด ์์๊น ์ถ๋ค. ํ๋ฉด์ด๋, Toast, SnackBar ๋ ธ์ถ๊ณผ ๊ฐ์ View์ ๋์๋ค์ ์๋ฏธํ๊ธฐ ๋๋ฌธ์ด๋ค. ViewEvent์ ๊ฒฐ๊ณผ๋ก ๋ง๋ค์ด์ง ์ ์๋ค.
reduce ํจ์๋ ViewState์ ViewEvent๋ฅผ ๋ฐ์์, ์๋ก์ด ViewState์ ViewEffect๋ฅผ ๋ฐํํ๋ค.
MVI์๋ ๋์ค๋ intent ๋ผ๋ ๊ฐ๋ ์ด ์ฝ๋ ์ ๊ตฌํ๋์ง ์์ ๊ฒ์ ๋ณด๊ณ , ์์ธํ ํ์ ํ๊ณ ์ถ์ด์ก๋ค.
MVI ๊ฐ๋ ์์์ View๋ Compose์ Screen์ผ๋ก ๋ณด๋ฉด ๋๊ฒ ๋ค. ์๋ View๊ฐ Intent๋ฅผ observeํ๋ค๋๋ฐ, ๊ตฌํ ์ฝ๋๋ฅผ ๋ณด๋ ํด๋ฆญ ์ด๋ฒคํธ ๊ฐ์ ์ฌ์ฉ์ ์ํธ์์ฉ ์ ๋ ฅ ์์ ๊ด๋ จํ ViewEvent๋ฅผ ์์ฑํด viewmodel๋ก ๋ณด๋ธ๋ค. Interaction์ Intent๋ก ๋ณด๋ ๋ฏ ํ๋ค. Model์ด ๋ฐ๋ก ์ํ(ViewState)๊ฒ ๋ค.
์์ ์ฝ๋๋ฅผ ๋ณด๋ค๊ฐ TimeMachine์ด๋ผ๋ ์กด์ฌ๋ ์๊ฒ ๋์๋ค.
์๋ฌธ์์ TimeMachine๊ณผ ๊ด๋ จํด ์ฐธ๊ณ ํ ๊ธ์ด๋ค.
https://medium.com/@VolodymyrSch/android-simple-mvi-implementation-with-jetpack-compose-5ee5d6fc4908
Android: Simple MVI implementation with Jetpack Compose
Foreword: There are different architectures for building a UI in Android development, but MVI is less known from them all. Studying the…
medium.com