Mobile Architectural Patterns

A general overview of architectural patterns for mobile, including MVC (current mobile app patterns), MVVM (RG-POC app uses this), and others.

TL;DR: Shifting from MVC to MVVM seems to be a solid direction for our Mobile applications, while other options like VIPER / Clean Architecture may over-specify abstractions in ways that would make distributed open-source development more difficult. Full steam ahead with MVVM (proposed)!


Key Coverage Areas:

1 - General overview of Mobile Architecture patterns and choices

2 - MVC vs MVVM Patterns

3 - TBD

4 - Mobile Architecture Resources and Reading

General Architecture Patterns Overview

When it comes to mobile application development, architecture patterns are essential for creating robust and scalable applications. The most common mobile architecture patterns used for iOS and Android applications are: MVC, MVVM, and Clean Architecture.

Model-View-Controller (MVC) Architecture

MVC is a widely used architecture pattern for building mobile applications. The model represents the data of the application, the view is responsible for the user interface, and the controller acts as an intermediary between the model and the view. The main advantage of using MVC is the separation of concerns, making the code more organized and easier to maintain.

Drawbacks: One of the major drawbacks of using MVC architecture for mobile development is that it can lead to massive view controllers that are difficult to manage and maintain. As the application grows more complex, the controller can become bloated with business logic, making it harder to understand and maintain. Additionally, because the view and controller are tightly coupled, it can be challenging to test them independently, which can make it harder to catch bugs and ensure that the application is functioning correctly.

Adoption: The MVC architecture pattern has been widely used for mobile app development since the early days of iOS in 2007 and Android in 2008.

Model-View-ViewModel (MVVM) Architecture

MVVM is another popular architecture pattern used for mobile app development. It is similar to the MVC pattern, but the view model replaces the controller as the mediator between the view and the model. The view model allows for better separation of concerns and enables the testing of the user interface without affecting the model.

Adoption: MVVM architecture patterns have been used for mobile app development for several years now, but it is difficult to pinpoint an exact date. It has gained popularity in recent years due to its advantages over the MVC pattern, such as better separation of concerns and testability.

Clean Architecture

Clean Architecture is a relatively new architecture pattern that provides a clear separation of concerns between the application's components. The layers within the Clean Architecture include the domain layer, use case layer, and presentation layer. The domain layer contains the business logic, the use case layer defines the application's functionality, and the presentation layer is responsible for the user interface.

Clean Architecture is a relatively new architecture pattern that was introduced by Robert C. Martin, also known as "Uncle Bob", in 2012. Both VIPER + VIP patterns are inspired by this original articulation of the architecture pattern.

https://medium.com/@jonas.schaude/developing-ios-applications-with-uncle-bobs-clean-architecture-572084853cdc

VIPER - Clean Architecture Example

The VIPER pattern stands for View, Interactor, Presenter, Entity, and Router. It is inspired by Clean Architecture in that it emphasizes the separation of concerns and the creation of well-defined layers within the application.

  • The View layer is responsible for displaying the user interface and handling user input.

  • The Interactor layer contains the business logic and interacts with the Entity layer, which represents the data of the application.

  • The Presenter layer acts as a mediator between the View and the Interactor.

  • The Router layer is responsible for navigating between different screens in the application.

Like Clean Architecture, the VIPER pattern provides a clear separation of concerns and makes the application more modular and easier to maintain. However, it is more complex than some of the other architecture patterns and can be more challenging to implement. Additionally, because each layer has a specific responsibility, there can be a lot of communication between the layers, which can lead to slower performance and increased complexity.

Overall, the VIPER pattern is a promising architecture pattern for mobile app development, and it shares many similarities with Clean Architecture. However, it is a more complex pattern that requires more planning and effort to implement effectively.

 

Specific Architecture Pattern Differences

  • MVC (Model-View-Controller) is a widely used architecture pattern for building mobile applications. The model represents the data of the application, the view is responsible for the user interface, and the controller acts as an intermediary between the model and the view. The main advantage of using MVC is the separation of concerns, making the code more organized and easier to maintain. However, one of its drawbacks is that it can lead to massive view controllers that are difficult to manage and maintain. Business logic can bloat the Controller as the application grows more complex which can make clarity and maintainability both issues for development teams. Additionally, because the view and controller are tightly coupled, it can be challenging to test them independently, which can make it harder to catch bugs and ensure that the application is functioning correctly.

  • MVVM is essentially an extension of the MVC pattern, with the ViewModel replacing the Controller. The ViewModel is responsible for providing data to the View and handling user interactions. By adding the ViewModel layer, the View and the Model are decoupled, which can make it easier to understand and maintain the codebase. This can lead to faster developer speed and increased developer satisfaction.

  • Clean Architecture is a more abstract approach that separates the application into layers, with each layer having a specific responsibility. The domain layer contains the business logic, the use case layer defines the application's functionality, and the presentation layer is responsible for the user interface. In contrast, While MVVM focuses primarily on the relationship between the View and the ViewModel, Clean Architecture provides a more comprehensive approach to separating the application's components, making it more flexible and easier to maintain in the long run. VIPER is an example variant of the Clean Architecture principles, defined by Mutual Mobile, it has specific rules for defining additional layers and abstractions that typifies Clean Architecture.

Mobile Architecture Resources + Reading

Here are a few resources to read for Clean Architecture for mobile application development: