Skip to content

Architectures

Hadi Mehrpouya edited this page Jan 28, 2025 · 8 revisions

Intro

Android apps are made of layers. layers are a way to break down different parts of an app to independent and more focused chunks or parts, bit like classes. ** Why like classes? ** Because they're not the same, but their concepts somehow relates. What you need to remember is that Android official language Kotlin is a domain based language.

Domain Based Language

What does that suppose to mean? This means, you can have 3 or 5 different words that they all mean "class" but each slightly different to each other. It's like making a language specialised for a specific platform or purpose. How is that different from any other language? What do you mean? They are all specialised languages, wouldn't you agree? Sure, ok, so think about it this way. Different cultures have specific words that they don't exist in other languages. You can't meaningfully translate them. Can you give me some examples? Not yet! I asked Gemini to describe it using a dialogue approach. this is what they said

Reactive architecture

Single Source of Truth (SSOT)

To protect your data, you create a separate layer to deal with all data retrieval and changes. This means, each app will have at least two layers. Single Source of Truth is a bit like Singleton design pattern, it means anytime you create a new datatype in your app, you also create a SSOT who will be the sole owner of that data and in chanrge of access to it and making changes.

To achieve this, the SSOT exposes the data using an immutable type, SSOT exposes functions or receive events that other types can call.

Unidirectional Data Flow (UDF)

Rmember this:

Events go in, states comes out.

This is about how data flows from its sources to UI and back. This is a bit like Gradle, it is about working out the bestr route for data retrieval and changes. state or data usually flow from the higher-scoped types of the hierarchy to the lower-scoped ones. Events are usually triggered from the lower-scoped types until they reach the SSOT for the corresponding data type.

UI State management

Here you need to develop your UI layer with an approach that your application and UI can deal with different mobile states.

Coroutines and flows

Can you give me some examples of layers?

UI layer

Think of them as images, they are dead. They are in a way static until an event happens. A touch, Scroll, changes to the background data of UIs. Some people call it presentation layer, which sounds better somehow.

Clone this wiki locally