Does anyone here still use MVP? If so, do you use ...
# android-architecture
Does anyone here still use MVP? If so, do you use databinding or LiveData? And what are your reasons for using MVP?
I'm in a legacy codebase that uses MVP and I would avoid it if you have the option. Do you have the option to choose MVVM?
I use MVP, databinding or LiveData has not so much to do with that. The reason I like MVP it that in Android the view itself carries a state and MVP is good in handling events, like "hey view, go update your state!". With MVVM you will have to battle the difference in state between your ViewModel and the actual View. Also Events like "show a dialog/snackbar" are a nuisance as those will probably have yet another lifecycle you have to state manage somehow from the state in your ViewModel. MVP has a nice abstraction between layers, as it forces you to write the contracts. Some people see this as boilerplate, but I think it is nice. The communication between my model and presenter uses LiveData, the communication between Presenter and View uses contractual methods, and the presenter lives and dies like the view (so easy to do testing, and a very low risk of memory leaks). I dislike databinding, as I think there should be no Java code in XML files. The ability to do so is weird to me and easy to abuse and horrible to test. I guess all in all, I rolled into a project with a very bad MVVM implementation and then chose to fallback to the one I am familiar with: MVP. If I would have to choose now, I would go with MVVM simply because of the arrival of Jetpack Compose there will be a UI framework that is stateless, so you can actually have your ViewModel as a single source of truth. Also Google provided tooling for MVVM so if you know the caveats of MVVM and you know a nice way around them, it will be anyway a stable pattern (just like MVP) and easy to use as well. @Nathan Retta what is your reason to avoid mvp?
đź‘Ť 4
If LiveData is how your model returns values to your presenter, to what Lifecycle is the LiveData scoped?
Typically in MVP, the View has a ref to the Presenter, and the Presenter has a ref to the View. But you wouldn’t need the latter if the View is just observing LiveData held in the presenter. So does your Presenter still have a ref to the View (even if only exposed as an interface)?
@Brady Aiello So the view exposes the (view) lifecycle owner, what the presenter uses to observe the data in the model. The view and the presenter have a reference to one another and that is how they communicate, through a direct invocation on functions in the contract. I also made my model under the hood to be ViewModel from the architecture components, so the data survives config changes.