Android Architecture Patterns

Tags: Architecture Patterns

By Tom Roe on December 26th, 2023

White building

Overview of architecture patterns

Organisation is key when it comes to any software project. Good architecture will help us in lots of areas as a project grows and we add more classes:

Simply put, the architecture is the foundation of the app. We decide how to split the code up into different sections, ideally before we've written the first line of code.

MVVM

MVVM diagram

MVVM (Model-View-ViewModel) is an architectural pattern often used in Android projects. I've personally been using it in all my new projects and use it during my 9-5 as well. It aims to separate the user interface (View) from the business logic (ViewModel) and data (Model). The ViewModel acts as an intermediary between the View and the Model, exposing data and commands that the View can bind to. As mentioned above, this separation allows for better testability, maintainability, and flexibility.

Clean Architecture

MVVM architecture can cause a project to become unweildy after it gets to a certain point. Very large projects can benefit from something called Clean Architecture, which focuses on the separation of concerns. The image below shows an example of this, although not all the layers need to be included as it will vary depending on the project.

Clean architecture diagram

A crucial point to note is that outer layers can refer to inner layers, but inner layers cannot refer to outer layers. 'The outer layers should depend on the higher order of ideas which is contained in the inner layer.' Let's look at