Andy Lu
Aug 21, 2021

--

的確,如果以這個 Case 來說,直接把 LiveData 放在 ViewModel ,BroadcastReceiver 直接呼叫更新即可。這樣不需要 Repository 這一層也可以達到相同的效果。

不過,增加 Repository 的用意是,如果我們的有多個資料來源, Repository 用來負責向各個來源去要資料,最後再把這些資料丟給 ViewModel ,換句話說,ViewModel 不 care 有哪些資料來源,他只在乎有哪個資料而已。

--

--

Andy Lu
Andy Lu

Written by Andy Lu

Android/Flutter developer, Kotlin Expert, like to learn and share.

No responses yet