Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MVP explanation

I try to understand what the best way is to program a "clean" Android app. I found an interesting article about it where they use a kind of a 3 layer architecture.

Now I read that android uses the MVP design pattern and try to understand this. The way I understand the MVP principle (in the android context) is that:

  • the Model layer are the logic classes
  • the presenter are the classes that are "linked" to an XML (the activities)
  • the passive view are the XML's.

Is this correct?

When this is correct, is it then also correct that the 3 layer model fits perfectly in the MVP principle because:

  1. the presentation layer from the 3 layer architecture fits in the presenter layer of MVP
  2. The business and the data layer from the 3 layer architecture fits perfectly in the model part of the MVP?

I hope my questions are clear because it is a complicated topic for me.

Maybe this clears up my vision (way of thinking) about this... Maybe this clears up my vision about this...

like image 338
CodeNinja Avatar asked Dec 28 '15 14:12

CodeNinja


2 Answers

first thing I wanted to clarify is that MVP or any other pattern for that matter is no specific of Android dev and, can be applied to any other framework.

I think you got the gist of it:

  • view is usually implemented by activities and fragments and will contain the reference to the presenter
  • the presenter is that middle man between the view and model. Retrieves data from the model and returns it already formatted to the view so it doesn't need to do anything else but display it.
  • the model can be seen in a simplistic way as the "data provider". It can be as complex as you want, using internal db, lots of clases etc.

If you are interested in Android apps architecture I suggest you watch this talk given at Android dev summit this year. It is one of the bests I've seen

https://www.youtube.com/watch?v=BlkJzgjzL0c

like image 191
Aitor Viana Avatar answered Oct 09 '22 15:10

Aitor Viana


Here is simplest way to implement MVP pattern in your application android_mvp_login_sample

like image 31
ramkrishna kushwaha Avatar answered Oct 09 '22 13:10

ramkrishna kushwaha