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

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[๊ธฐ์ˆ  ๋ธ”๋กœ๊ทธ ์ฝ๊ธฐ] robust + MVI + Jetpack Compose

์ฝ์€ ๊ธฐ์ˆ  ๋ธ”๋กœ๊ทธ ์›๋ฌธ + ์ถœ์ฒ˜

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 ์‚ฌ์ „์  ๋œป๋„ ๋ณด๊ณ 

๋„ค์ด๋ฒ„ ์˜์–ด ์‚ฌ์ „์—์„œ์˜ robust ๋œป

 

 

์†Œํ”„ํŠธ์›จ์–ด ๊ด€๋ จํ•ด์„œ ์–ด๋–ป๊ฒŒ ์“ฐ์ด๋Š”์ง€๋„ ์‚ดํŽด๋ณด์•˜๋‹ค.

 

์œ„ํ‚คํ”ผ๋””์•„์—์„œ์˜ ๋œป : Robustness๋„ ํ™•์ธํ•œ๋‹ค.

์œ„ํ‚คํ”ผ๋””์•„์—์„œ์˜ 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์„ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฑด ์•Œ๊ณ  ์žˆ์—ˆ๋‹ค.

https://medium.com/@dnjstjr245/%EB%B2%88%EC%97%AD-data-binding%EC%9D%84-%EC%82%AC%EC%9A%A9%ED%95%98%EC%A7%80-%EB%A7%90%EC%95%84%EC%95%BC-%ED%95%98%EB%8A%94-%EC%9D%B4%EC%9C%A0-85b91d7e8b6b

 

(๋ฒˆ์—ญ) Data Binding์„ ์‚ฌ์šฉํ•˜์ง€ ๋ง์•„์•ผ ํ•˜๋Š” ์ด์œ 

์›๋ฌธ : https://medium.com/p/cf3c439637c

medium.com

 

2. Jetpack Compose์™€ XMl ๊ฐ„ ๋น„๊ต. Jetpack Compose์˜ ์žฅ์ ๋“ค์— ์ง‘์ค‘ํ•ด์•ผ ๊ฒ ๋‹ค.

https://medium.com/@MeenoTeK/xml-views-or-jetpack-compose-which-is-the-best-option-for-your-next-project-ccf38573a82

 

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๊ฐ€ ์ข‹๋‹ค๋Š” ๊ธ€์„ ์ฐพ๋Š” ๋ดค๋‹ค. ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ๋“ฑ ๋ชจ๋“ˆ ๊ณต์œ ๊ฐ€ ๋‹ค์–‘ํ•œ ํ”Œ๋žซํผ ๊ฐ„ ๊ฐ€๋Šฅํ•˜๋Š” ๊ฒƒ์ด ์•„ํ‚คํ…์ฒ˜๋ฅผ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์€ ์žฅ์ ์ธ ๊ฒƒ ๊ฐ™๋‹ค.

https://blog.stackademic.com/the-unique-advantages-of-kotlin-multiplatform-over-other-cross-platform-solutions-2d843c2813d5

 

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 ์ฐธ๊ณ 

https://jaehochoe.medium.com/%EB%B2%88%EC%97%AD-%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C%EB%A5%BC-%EC%9C%84%ED%95%9C-mvi-model-view-intent-%EC%95%84%ED%82%A4%ED%85%8D%EC%B3%90-%ED%8A%9C%ED%86%A0%EB%A6%AC%EC%96%BC-%EC%8B%9C%EC%9E%91%ED%95%98%EA%B8%B0-165bda9dfbe7

 

[๋ฒˆ์—ญ] ์•ˆ๋“œ๋กœ์ด๋“œ๋ฅผ ์œ„ํ•œ 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