Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Android:

MVC is a design pattern. In that, Model is responsible for managing data of thee application. In android,
model is sqlite database, API service, share preference, content provider, and the objects in the
application.

View is responsible for rendering UI and communicate to the controller when user interact with the
application. View displays the data that is received from the controller as the outcome

Controller is responsible to process incoming requests. When the view tells the controller that user
clicked a button, the controller decides how to interact with the model accordingly. Based on data
changing in the model, the controller may decide to update state of the views. In android, the controller
represented by an Activity or Fragment MVC does a great job of separating the model and view.
However, the controller is tied so tightly to View. If we change the view, we have to go back and change
the controller. It is difficult for maintenance, because all code relates to business logic and code interact
with View are written on controller – Activity of android. It is difficult to unit test.

MVP

Model in MVP same as MVC

View: In MVP, Android Activity and Fragment are now considered part of the View. Activity implement
view interfaces and renders the data in a way they want. Presenter: different from controller, it is not
tied to a View, only process code logic, Presenter communicates with View through interface. So we
easily write unit test, review code

MVVM pattern support two-way data binding between View and ViewModel Model same as MVC and
MVP

View binds to observable variables and actions exposed by ViewModel ViewModel is responsible for
wrapping the model and preparing observable data needed by the View. It also provides hooks for the
view to pass events to model. View has a reference to ViewModel but ViewModel has no reference to
View. It is not tied to the View. So it can easily write unit test. When testing, we only need to verify the
observable variables when the model changes Both MVP and MVVM do a better job than MVC. MVP
and MVVM which pattern is best for us? MVP use interface implemented in Activity to update UI while
MVP use observable variables in ViewModel to update UI. And both MVP and MVVM is easily to do unit
test and review code. So, choosing MVP or MVVM base on our personal preference.

You might also like