Common Software Architecture patterns in Mobile Application Development.
Tags: mobile, android, hng
Published: 2024-07-03 16:01:27


Architecture refers to a set of techniques that are used to combine the different parts of a software application. It can be defined as the internal structure of a software application. It describes how different software components communicate with each other to process input and produce output to the user.  A mobile application is a software application that is designed to be used on a mobile device. Mobile application architecture is a combination of models and techniques used to build a mobile application ecosystem. There are many software architecture patterns, however there are peculiar ones that are more suitable for mobile applications.

**Major Components of a Mobile App**
The major components within a mobile application are the basic building blocks upon which application architecture can be designed. These components act as multiple layers that communicate with each other through which data passes on to trigger different functionalities within the mobile ecosystem. Both IOS and Android, which are the two main Mobile Operating Systems, use this pattern.
The three main components of a mobile app are:

- Presentation Layer
- Business Layer
- Data Layer

**Presentation Layer**
The Presentation layer defines how an application is presented to the end user. It is a user interface and communication layer where the user can interact with the application. Every mobile device has a screen and this is the component that displays information to the user. It is also known as the frontend of an application.
The main purpose of the presentation layer is to take the data sent by the business layer and display it in a way the user understands.

**Business Layer**
The business layer is the logic behind which the application operates. It instructs the application on what functions it should exhibit. It often takes user input or raw data from the data layer, processes it, then sends it to the presentation layer. Examples of functions of this layer include logging, authentication/ authorization, data caching, security, data validation, and exception management.



**Data Layer**
The data layer is an intermediary between the business layer, presentation layer and external resources. Its main purpose is to obtain raw data from various sources (such as a database, cloud server, or an API). This layer consists of various components like service agents, data access components, data utilities, to enable data transactions within an app.

**Architectural Patterns**
Examples of Architectural patterns include:
- Model-View-Presenter (MVP)
- Model-View-Controller (MVC)
- Model-View-ViewModel (MVVM)
- VIPER (View, Interactor, Presenter, Entity, Router)

**Model-View-Presenter**
This is an architecture that consists of the three major components of a mobile application. The model which is the data layer and it manages the business logic and data. The View is the presentation layer which displays information to the user. The Presenter is a component that handles user actions and updates the view with data from the model layer.

**Pros:**
- Better separation of concerns compared to MVC.
- Easier to test because the Presenter can be tested independently of the Android framework.

**Cons:**
- Can lead to complex Presenter logic.
- More boilerplate code compared to MVC.


**Model-View-Controller**
In this architecture the Model represents the business logic and user data. The View handles presentation of data to the user. The Controller handles the user input and interacts with the model to update the view. The purpose of this architecture is to separate business logic from presentation logic which allows the code to be more readable, debuggable and easy to update.

**Pros:**
- Separation of concerns.
- Easy to understand and implement.

**Cons:**
- Can lead to bloated controllers.
- Not suitable for complex applications with heavy UI logic.


**Model-View-ViewModel**
This architecture is the recommended architecture by Android. It is also used in native IOS development for mobile devices. It separates the application into three parts which are Model, View, and ViewModel. The Model is concerned with managing data and business logic. The View handles presentation logic binding view properties to the  data exposed by the ViewModel while the ViewModel interfaces between the Model and the View, which contains the reference logic.

**Pros:**
- Clear separation of concerns.
- Facilitates data binding.
- Easier to test compared to MVC and MVP.

**Cons:**
- Requires understanding of data binding frameworks.


**VIPER (View, Interactor, Presenter, Entity, Router)**
This is an architecture pattern that separates the app's functionalities into five distinct components namely View, Interactor, Presenter, Entity and Router.
The View displays the presenter information while user input to the presenter. The Interactor handles the business logic. The Presenter gets data from the interactor and sends it to the view for display. The Entity is the business model that describes the entities to be used by the interactor. The Router handles how data is navigated within the application.
**Pros:**
- Promotes clean architecture with a clear separation of concerns.
- Each component has a single responsibility.
**Cons:**
- Can be complex to set up and maintain.
- May introduce a lot of boilerplate code.

**Conclusion**
In conclusion Model-View-ViewModel is the most commonly used architectural pattern in mobile application development.  Also it is the recommended architecture for Android mobile applications by Google.
As an intern at the ongoing cohort of the HNG 11 internship I hope to refresh my technical skills in the art of crafting reliable, durable and testable software applications that can be used to solve real world problems. Given my background in software development I hope to make a mark by skilling up through this great initiative and also to give back by helping others solve their problems through software development. You can check out the program [here](https://hng.tech/internship). There is also a premium version of the internship where you get exclusive benefits and a certificate you can see [here]( https://hng.tech/premium) for the premium version.