I have an application with MVP architectural pattern. Now, I am trying to implement Livedata in my application. I searched a lot , but I can not found any tutorial or example for this. All tutorial says live data is for MVVM pattern.
Applying Livedata in MVP pattern is a correct method or not?
If anyone have idea about implementing Livedata in MVP please share.
Thanks in advance.
Using livedata instead of MVPview in MVP makes the presenter loosely coupled with the view and helps in reusing presenter. We can create different presenter for different components and expose events using livedata, it also encourages reactive architecure.
MVP (Model — View — Presenter) architecture is one of the most popular architecture patterns and is valid in organizing the project. MVP (Model — View — Presenter) comes into the picture as an alternative to the traditional MVC (Model — View — Controller) architecture pattern.
Difference Between MVP and MVVM Design PatternMultiple View can be mapped with single ViewModel. The Presenter has knowledge about the View. ViewModel has no reference to the View. Model layer returns the response of the user's input to the Presenter which forwards it to View.
MVVM is better than MVC/MVP because of its unidirectional data and dependency flow. Dependency is one way, thus it is a lot easier to decouple it when we need to. It is also easier for testing. All my projects(written in Kotlin for Android app) are based on MVVM.
Lifecycle aware MVP is a good solution.
As you know Architecture Components introduce LiveData, a lifecycle-aware observable data holder class - the idea is great and sounds super handy. AC causes some "additional code to handle null case in our onChanged implementations" and also it's "harder to read and understand the flow" in the code.
Lifecycle aware MVP solve mentioned issues with these benefits:
so if you have an existing MVP architecture and want to make use of ViewModels and their handling of configuration changes, this is an easy way to do achieve it
you can find more about it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With