Layered Architecture — Android app architecture by example Part 3/5

Ashesh Bharadwaj
3 min readMar 19, 2019

--

Software architecture is the art of drawing lines that I call boundaries — Robert C. Martin

This is the third article of a five-article series on Android app architecture:

  1. What is Architecture?
  2. Programming principles
  3. Layered Architecture (you are here)
  4. Clean Architecture
  5. Sample app
Photo by Sean Stratton on Unsplash

Architecture is about putting the classes behind boundaries and how they communicate with each other through the boundaries.

I guess at some point most of us would have wondered looking at the project tree structure folders in Android Studio, how these folders/packages are named? Why someone is naming a package service and other is using background? Packages play an important role in the architecture as it helps us to organize related classes and present them as an interface.

Our journey to implement an architecture knowingly or unknowingly starts when we start putting activities/fragments in ui package. This is the beginning where we acknowledge the need of an architecture.

As I have mentioned before, separation of concerns is one of the guiding principles of programming. By putting the classes in a package we introduce them as a single component. We make these classes focus on a single concern. This grouping of classes can be called as a layer. We create layers so that we can organize classes which serve the same purpose.

Layered architecture pattern comes naturally to us. We start putting similar classes into packages which can be called a layer. There could be n number of layers but at a minimum we require 3 layers.

  1. UI layer: Here we can put activities, fragments, adapters and any other classes related to the user interface.
  2. Domain layer: Here we can put the business logic of our app. The code which is exclusive to our app.
  3. Data layer: The database related classes and any other system service.

The goal in a layered architecture is to create boundaries where one layer only interacts with adjacent layer and this happens in a single direction.

Each layer interacts with adjacent layer and the flow is in single direction

This means UI layer can’t directly interact with Data layer. This isolation helps us to minimize the impact of changes. Although there are cases where we can have an open layer which can be bypassed but more or less we follow interaction to the adjacent layer in a single direction.

This is a very simple architecture pattern which can be implemented with minimal effort. This is the reason Google guide to app architecture also recommends a similar app architecture. This will help the beginners to start with an architecture.

The interaction diagram recommended by Google “Guide to app architecture”

In the next part we will see a more evolved architecture pattern: Clean Architecture.

Thanks for reading this article. You can connect with me on LinkedIn and Twitter

If you like this article, please recommend it by hitting the clap icon as many times you wish 👏 Let’s enable each other with the power of knowledge.

📝 Read this story later in Journal.

👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.

--

--

Ashesh Bharadwaj

Google Certified Android Developer, enjoying the journey to the future of personal data space. www.linkedin.com/in/asheshb