แอป Android ได้ประโยชน์จาก architecture pattern ที่แยกความรับผิดชอบและเพิ่มความสามารถในการดูแลรักษาและการทดสอบ ที่โดดเด่นได้แก่ MVVM (Model-View-ViewModel ซึ่ง Google แนะนำ), MVI (Model-View-Intent) และ Clean Architecture การเข้าใจสิ่งเหล่านี้สำคัญต่อการสร้างแอปที่มีโครงสร้างดี
MVVM — Model-View-ViewModel (แนะนำ)
MVVM separates the UI from logic and data:
VIEW (Activity/Fragment/Compose) → displays UI, observes the ViewModel, forwards events
VIEWMODEL → holds UI state + logic; exposes observable state (LiveData/StateFlow);
survives config changes; NO Android framework/UI dependencies (testable)
MODEL → data (repositories, data sources)
→ The View observes the ViewModel's state and updates reactively. Google's recommended
pattern (using Architecture Components).
