Skip to content

Architecture

Albert Pinto edited this page Jul 13, 2021 · 1 revision

When developing Android apps, we need to define an architecture that defines the way classes are organised and their interactions. We have used the Clean Architecture with Model-View-ViewModel (MVVM)

Clean architecture

In this architecture, the application is organized in layers, with the constraint that each one can only know the inner layers.

Source: https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

The entities, also known as models, are the most inner layer; thus, the others might have instances of the models. In large Android applications, the layers might be separated by modules. However, since the project is relatively small, we have decided to use just packages instead.

Suppose we have 3 classes named A, B, and C, which belong to the Controllers, Use Cases and Entities layers. The following relations are possible:

  • A -> B
  • A -> C
  • B -> C

The arrow indicates that the first-class might have an instance of the second one as a property. However, the following relations are impossible:

  • C -> B
  • C -> A
  • B -> A

To communicate with an outer layer, we have to use an interface, which has to be injected into the constructor. In the project, we will always use constructor injection, except for fragments. (See Dependency Injection for more information)

Execution flow

In the project, we are going to use a 5 layer architecture:

  • Fragment: displays the components and respond to user interactions
  • ViewModel: controls the fragment logic
  • Use cases: performs an action in the application
  • Repository: hides the interaction to local databases and APIs to the use case, following the Repository Pattern
  • DataSource: it can be either the LocalDataSource or the RemoteDataSource, which will interact with local databases and remote APIs respectively using the DAO pattern

Source: https://www.toptal.com/android/android-apps-mvvm-with-clean-architecture

Clone this wiki locally