22 AndroidArchitecture
22 AndroidArchitecture
Contents
● Architecture
● MVP
● MVVM
Architecture
Architecture
Sample application
MVC Pattern Architecture
6
MVC components
• Model: represents a set of classes that describe the business logic
• View: represents the UI components
• Controller:
– is responsible to process incoming requests.
– It receives input from users via the View, then process the user's data with the help of
Model and passing the results back to the View.
– it acts as the coordinator between the View and the Model.
– There is One-to-Many relationship between Controller and View, means one controller
can handle many views
MVC - Model
MVC - View
MVC - Controller
MVC - Advantages
• Easy to maintain, test and upgrade the multiple system.
• Easy to add new clients just by adding their views and
controllers.
• Be able to have development process in parallel for model, view and
controller.
• Make the application extensible and scalable.
11
MVC - Disadvantages
12
MVP Pattern
•Model-View-Presenter (MVP) is a variation of the Model-View- Controller
(MVC) pattern.
•The primary differentiator of MVP is that the Presenter implements an
Observer design of MVC but the basic ideas of MVC remain the same:
– the model stores the data
– the view shows a representation of the model
– the presenter coordinates communications between the layers.
MVP Pattern Architecture
14
MVP components
•Model: The model in MVP is the same as MVC
•Presenter:
– handle user input and use this to manipulate the model data.
– interactions of the User are first received by the view and then passed to the
presenter for interpretation
– there is One-to-One relationship between View and Presenter
•View: When the model is updated, the view also has to be updated to reflect the changes
Passive view and Supervising Controller
•The Model-View-Presenter variants: Passive View and Supervising
Controller
•In Passive View:
– the presenter updates the view to reflect changes in the model.
– The interaction with the model is handled exclusively by the presenter.
– The view is not aware of changes in the model.
•In Supervising Controller:
– the view interacts directly with the model to perform simple data-binding that can be defined
declaratively, without presenter intervention.
– The presenter updates the model
– it manipulates the state of the view only in cases where complex UI logic that cannot be specified
declaratively is required.
MVP - Model
MVP - View
MVP - View
MVP - Presenter
Advantages of MVP
• it clarifies the structure of our user interface code and can make it easier to
maintain.
• almost all complex screen logic will reside in the Presenter.
• We have almost no code in our View apart from screen drawing code Model-
View-Presenter also makes it theoretically much easier to replace user
interface components, whole screens, or even the whole user interface
• It is features can be enhanced separately with more involvement
21 from the
customer.
• In addition, unit testing the user interface becomes much easier as we can test
the logic by just testing the Presenter.
MVVM Pattern
23
MVVM Architecture
MVVM components
•Model:
– It represents the data and the business logic of the Android Application
– It consists of the business logic - local and remote data source, model
classes, repository.
•View:
– It consists of the UI Code(Activity, Fragment), XML
– It sends the user action to the ViewModel but does not get the response back
directly
– To get the response, it has to subscribe to the observables which ViewModel
exposes to it
MVVM components
•ViewModel :
– is a bridge between the View and Model
– It does not have any clue which View has to use it as it does not have a
direct reference to the View
– It interacts with the Model and exposes the observable that can be observed
by the View
MVVM - Model
MVVM - View
MVVM - View
MVVM - ViewModel
Advantages of MVVM
31
Disadvantages of MVVM
32
Summary
33
References
● https://www.vogella.com/tutorials/AndroidArchitecture/article.html
● https://www.slideshare.net/mudasirqazi00/design-patterns-mvc-mvp-a
nd-mvvm?from_action=save
● https://www.vogella.com/tutorials/AndroidArchitecture/article.html
● https://academy.realm.io/posts/eric-maxwell-mvc-mvp-and-mvvm-on-
android/