Android Architecture Patterns

Ewigsol
3 min readAug 27, 2021

Today we are discussing about the android architecture patterns

When the dynamic nature developers work on a real mobile application who will expand its features and capabilities according to the need of user, then there is no possibility to write core logic in fragments or activities. To structure the code of project and to give it a modular design, architecture patterns are applied to separate the concerns.

MVC(MODEL VIEW CONTROLLER)

MVP(MODEL VIEW PRESENTER)

MVVM(MODEL VIEW VIEW-MODEL)

MVC (MODEL VIEW CONTROLLER):

It is the old android app architecture which suggests the separating the codes simply in 3 layers

· MODEL:

It is the layer for storing the data and the responsibility is to handling the domain logic and communication with the database and network layers.

· VIEW:

It is a user interface layer and it provide the visualization of the data stored in the model.

· CONTROLLER:

It is the layer which consists of core logic and it get information about the user’s behavior and also updates the model according to the need.

In MVC schema, Controller and view both depend upon Model. The data of the Application is updated by View and Controller gets the data. In this pattern, the Model can be tested independently of the UI as it is separated

The advantages of MVC are;
Advantages:

· If the View respect the single responsibility principle then the functionalities of the View can be checked through UI tests

· The pattern of MVC increases the code of testability and then makes it easier to implement the new features because it highly supports the separation of concerns.

Disadvantages:

· There is no parameter to handle the user interface logic

· The layers of Code depend upon each other even if MVC is applied correctly.

MVP (MODEL VIEW PRESENTER):

It is the second pattern in android app architecture. This pattern is widely accepted and till now is the recommended for upcoming developers. It is also separated in 3 parts;

· MODEL:

This layer is used for storing the data and the responsibility is to handling the domain logic and the communication with network layers and database.

· VIEW:

It is the layer for user interface and it provides the visualization of data and then keep the track of the action of user.

· PRESENTER:

This layer fetch the data the model and applies it to the UI logic to make decision for the display.

Advantages:

· MVP is easy code maintenance and testing as the view, application’s model and the presenter layer are separated.

· There is no conceptual relationship in the android components

Disadvantages:

· The main disadvantage is if the developer does not follow the single responsibility principle to break code and then Presenter layer tends to expand to a huge all-knowing class.

MVVM (MODEL VIEW VIEW-MODEL):

Model view view-model is the third iteration of android architecture and white the releasing of android architecture components, the android team recommended the architecture pattern. So the code layers are;

· MODEL:

The responsibility of this layer is the abstraction of data sources and the ViewModel and model work together to save and get the data.

· VIEW:

The main purpose of this layer is to inform the ViewModel about the action of the user.

· VIEW-MODEL:

This layer expose that data streams which are relevant to the view.

The MVP and MVVM patterns are quite both similar because they are efficient in abstracting the behavior and state of the View layer. In MVVM, the views can bind itself to the data streams that are exposed by ViewModel.

--

--

Ewigsol
0 Followers

We develop and launch your business online. We build websites, mobile apps, software and also help them in marketing them with our resourceful It solutions