Android Application Architecture Flashcards

1
Q

What is MVP and how to different from MVC ?

A

The Model View Presenter (MVP) architecture pattern improve the application architecture to increase testability. The MVP pattern separates the data model, from a view through a presenter.

  1. ## The viewA view component in MVP contains a visual part of the application.

It contains only the UI and it does not contain any logic or knowledge of the data displayed.

In typical implementations the view components in MVP exports an interface that is used by the Presenter.

The presenter uses these interface methods to manipulate the view. Example method names would be: showProgressBar, updateData.

  1. ## The presenterThe presenter triggers the business logic and tells the view when to update.

It therefore interacts with the model and fetches and transforms data from the model to update the view. The presenter should not have, if possible, a dependency to the Android SDK.

  1. ## The modelContains a data provider and the code to fetch and update the data.

This part of MVP updates the database or communicate with a webserver.

MVP makes it easier to test your presenter logic and to replace dependencies. But using MVP also comes with a costs, it makes your application code longer. Also as the standard Android templates at the moment do not use this approach, not every Android developer will find this code structure easy to understand.

In the Model View Presenter pattern, the views more separated from the model. The presenter communicates between model and view. This makes it easier to create unit tests Generally there is a one to one mapping between view and Presenter, but it is also possible to use multiple presenters for complex views.

In the Model View Controller pattern, the controllers are behavior based and can share multiple views. View can communicate directly with the model.

MVP is currently on of the patterns that the Android community prefers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is MVVM and how to different from MVP ?

A

The Model View View Model design pattern is also known as Model View Binder.

  1. The view
    - —————–

A view component in MVP contains a visual part of the application.

The view binds to observable variables and actions exposed by the view model typically using the data binding framework.

The view is responsible for handling for example:

Menus
Permissions
Event listeners
Showing dialogs, Toasts, Snackbars
Working with Android View and Widget
Starting activities
All functionality which is related to the Android Context

  1. The view model
    - ————————————–

The view model contains the data required for the view.
It is an abstraction of the view and exposes public properties and commands.

It uses observable data to notify the view about changes.

It also allows to pass events to the model.

It is also a value converter from the raw model data to presentation-friendly properties.

The view model has the following responsibilities:

Exposing data
Exposing state (progress, offline, empty, error, etc)
Handling visibility
Input validation
Executing calls to the model
Executing methods in the view

The view model should only know about the application context. the application context can:

Start a service
Bind to a service
Send a broadcast
Register a broadcast receiver
Load resource values
It cannot:
Show a dialog
Start an activity
Inflate a layout

  1. The model
    - ———————–

Contains a data provider and the code to fetch and update the data. The data can be retrieved from different sources, for example:

REST API
Realm db
SQLite db
Handles broadcast
Shared Preferences
Firebase
etc.

Basically the same as the model in the MVP.

  1. MVVM uses data binding and is therefore a more event driven architecture.
  2. MVP typically has a one to one mapping between the presenter and the view, while MVVM can map many views to one view model.
  3. In MVVM the view model has no reference to the view, while in MVP the view knows the presenter.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly