All articles
Clean architecture in Android

What is Android Clean Architecture?

Estimated read time: 6 minutes

Interested in an Android clean architecture guide?

You’ve come to the right place.

Choosing the right architecture is key to creating a great software application, this is why it is so important to get it right. Let’s first start with the challenges of using an android app architecture.

Android app architectural challenges

Android app development projects encounter architectural challenges like any other software development project does. These challenges arise from incorrect decision-making. A brief summary of these challenges is as follows:

  • Favoring status quo: Project teams sometimes stick to the status quo despite the architecture not quite working.
  • Over-architecting the solution: The large effort spent upfront on architecture delays the project.
  • Joining the microservices bandwagon: Netflix uses this pattern to great effect. That doesn’t mean all apps will be successful with it. I have earlier explained the pros and cons of the microservices architecture pattern in “10 best practices for building a microservice architecture”.
  • Choosing a pattern just because the team knows it, even though its’ not suitable for the app.
  • Frequent obsolescence of technology.

Read more about these challenges in “Solution architect’s challenges and common mistakes”.

Why did “Clean Architecture” emerge?

An understanding of the reasons that gave rise to “Clean Architecture” is useful upfront. So, here we go:

  • “Separation of concerns” has always been a key principle for software architects. An example will help in understanding this.
  • Let’s consider the rule that the business logic should never concern itself with the “User Interface” (UI) logic. Similarly, the UI logic should not concern itself with the business logic.
  • While the above principle makes perfect sense, in practice things turn out quite differently! Business logic code often deals with UI aspects like color and font size.
  • Software architects came up with the “Layered Architecture” pattern to solve this. Here, data enters the top layer. It flows through the intermediate layers, which have their own tasks. The data finally reaches the innermost layer, which is typically the database. Read more about layered architecture in “Large enterprise Java projects architecture”.
  • Let’s assume that we have a layered architecture, with the UI or the presentation layer being the outer layer. The middle layer is where the objects reside, and we can call it the “Business Logic Layer” (BLL). The inner layer has the database.
  • Here, changes to the BLL can dictate changes to UI. While that’s acceptable, small look-and-feel changes to the UI shouldn’t cause changes to the BLL.
  • During the execution, user actions will trigger certain processing in the BLL. As a result, some persistent changes to the data will be saved in the database.
  • However, if you try to manage these same dependencies during the compile-time, you lock yourself in with a specific database vendor. This reduces your choices.
  • Moreover, developers might often mix up data access code with other code performing different calculations. As a result, the testability of the application reduces.

Read more about these challenges in “An introduction to Clean Architecture”. The software architect community needed to find resolutions to these. Enter “Clean Architecture”.

Hire expert developers for your next project

Trusted by

A brief history of “Clean Architecture”

We have now summarized the challenges of traditional architecture patterns, as follows:

  • Unwieldy coupling of UI with other layers;
  • Coupling of the business logic layer to factors such as persistent storage;
  • Diminishing testability.

Robert C. Martin, also known as “Uncle Bob” presented the solution in 2011, and he called it “Clean Architecture”. Read his article in “Clean architecture”. In 2012, he expanded on his solution definition and presented the schematic diagrams of android architecture components to explain it.

Read “The clean architecture” for more information.

What is “Clean Architecture”?

a diagram illustrating clean architecture

A “Clean Architecture” is a pattern where all the layers look like an onion. The dependency rule is such that the inner layer shouldn’t concern about the outer layer. No code in an inner layer can directly reference any code from the outer layer.

On the contrary, an outer layer can talk to the inner layer. In other words, the dependencies point inwards. Read this Quora Q&A thread for more information.

In practice, this would mean the following:

  • The outermost layer, consisting of frameworks and drivers, talks to the next inner layer.
  • Let’s assume that this second layer is made up of the interface adapters.
  • This second layer will then talk to the next inner layer. This will be the layer of application business rules.
  • The third layer then talks to the innermost layer, where entities reside.

Advantages of “Clean Architecture”

“Clean Architecture” provides you with the following advantages:

  • Communication and clarity: As you can see, business use cases are most easily visible. This provides excellent clarity.
  • Flexibility: You are no longer tied to frameworks, database vendors, or application server providers. You can change any of these without any adverse impact.
  • Clean architecture helps in “Domain-driven design” (DDD). DDD is important for complex projects since the focus is on the core domain and associated logic.
  • Testing becomes easier since you can set up the scope of testing according to your requirements. You can test all the interfaces and outside interactions.

Read more about these advantages in “Clean architecture is screaming”.

Hire expert developers for your next project

62 Expert dev teams,
1,200 top developers
350+ Businesses trusted
us since 2016

Why consider “Clean Architecture” in Android development?

Let’s now narrow down our discussion to Android development. Why should you consider “Clean Architecture” here? The reasons are as follows:

  • “Separation of concerns” was the most fundamental design premise that we had started off with. By now, you can see how “Clean Architecture” addresses this.
  • This pattern makes the package structure easy to navigate.
  • Testers of Android apps find their job easier with “Clean Architecture”. There is a noticeable increase in test coverage.
  • The code is easier to maintain.
  • Having neatly compartmentalized the presentation layer, business logic layer, and entities, the project team finds it easier to move forward with their work.
  • Classes, including test classes, are focused.
  • Changes to UI can continue as the business requirements demand. These changes and their testing can continue in a stable environment.
  • Future strategic changes are easier since there is no dependence on the framework or database vendors.

Read more about these reasons in “A quick introduction to clean architecture”.

“Clean Architecture” has drawbacks too!

No software architecture pattern is without drawbacks. “Clean Architecture” has its’ share of pitfalls too, which are as follows:

  • Complexity: The plain reality with many apps is that most of the time the app just deals with data consumption. This means that there is not much business logic at play. Most operations are “Read” queries on a database, whereas some are “Write” operations. “Clean Architecture” stresses on use cases. If the software architect creates use cases for each of these “read” and “write” operations, then the number of use cases will be really high! In other words, you are likely introducing much more complexity than the app calls for.
  • Confusing “Clean Architecture” with modularity: Okay, sometimes there is real business logic and not just CRUD operations. Even then, if making your design modular is what your concern is, you have other ways to do so. You will still be able to separate the code between layers, and testability will still be okay. Even here, you can avoid the complexity of “Clean Architecture”, and just write modular code.
  • Boilerplates: Many software development experts urge us to avoid boilerplates. Now, it’s inevitable with “Clean Architecture” where you tend to introduce more boilerplates. Once again, the key question is whether you need them?
  • Duplicate models: This is closely related to the above pitfalls. You will end up creating similar models under each layer. You should once again ask whether you indeed need this complexity.

Read more about these drawbacks in “Downsides of clean architecture”.

Planning to implement Clean Architecture in your Android project?

“Clean Architecture” offers several advantages, however, it’s not the proverbial magic wand. First of all, you need to analyze whether your app is complex enough to merit this architectural approach. You should undertake a careful analysis of the use cases, CRUD operations, dependencies, etc. before you plan to use this approach.

Thereafter, you should pay enough attention to planning the various aspects such as the data flow through the data layer, and various layers. The domain layer is clearly the most important, however, you can’t cut corners while planning the other layers. Keeping all dependencies focusing inwards isn’t an easy task either.

You need the required software architecture expertise. That’s a niche skill! Consider engaging a reliable software development partner. You can read our guide “How to find the best software development company?” before engaging such a development partner.

If you are still looking for an experienced software development partner, contact DevTeam.Space through this quick form stating your initial Android development requirements. One of our account managers will help you partner with our field-expert software developer community for developing quality code for your next market-competitive android app.

Further Reading

Here are a few articles that might also interest you:

Hire expert developers for your next project

Trusted by

Are you wondering how to write a product requirements document? The modern software product development process requires flawless communication between the management and the development/testing teams. A...

Continue reading

Are you wondering how to write a functional specification document?  The good news is that you have come to the right place. Nailing your functional specifications document is vital if you want to build a great new app. A...

Continue reading

https://www.devteam.space/blog/how-to-use-blockchain-to-build-a-scalable-database/

Interested in how to use blockchain technology for identity? This is a market where software companies can really make a diffence. An Identity Fraud Report published by the Javelin Organization earlier this year highlighted the...

Continue reading

Frequently Asked Questions

Which architecture is best for Android?

For small apps use MVVM. However, for larger apps, MVVM is combined with clean architecture. For more information, read this article.

What is Android clean architecture?

This term refers to a set of practices that result in high-quality apps with the following characteristics: testable, UI-independent functionality, database independence, frameworks, external agencies, libraries, and classes like repository class.

What is the Android application architecture?

This refers to the design plan of an Android app. Essentially, it is a plan or map that relates to how the app and its respective parts or functions interact.


Alexey

Alexey Semeney

Founder of DevTeam.Space

gsma fi band

Hire Alexey and His Team
To Build a Great Product

Alexey is the founder of DevTeam.Space. He is award nominee among TOP 26 mentors of FI's 'Global Startup Mentor Awards'.

Hire Expert Developers

Some of our projects

Fitness App

100K+

Paying users

United States

Android, Android Kotlin, Health, iOS, Mobile, QA, Swift

A mobile fitness app for a famous YouTube blogger. 100K paying users within two weeks.

Details
Telecommunication Management Center

Enterprise

United States

Backend, Communication, DevOps, Java, Software

Designing, implementing, and maintaining continuous integration for an enterprise multi-component telecommunications web application.

Details
Cryptocurrency Exchange

Blockchain

United States

Blockchain, Ethereum, Fintech, Javascript, React, Smart Contracts, Solidity, Trading, Truffle, Web

A cryptocurrency wallet and an exchange platform to trade fiat currencies and crypto tokens.

Details

Read about DevTeamSpace:

Forbes

New Internet Unicorns Will Be Built Remotely

Huffpost

DevTeam.Space’s goal is to be the most well-organized solution for outsourcing

Inc

The Tricks To Hiring and Managing a Virtual Work Force

Business Insider

DevTeam.Space Explains How to Structure Remote Team Management

With love from Florida 🌴

Tell Us About Your Challenge & Get a Free Strategy Session

Hire Expert Developers
banner-img
Get a complimentary discovery call and a free ballpark estimate for your project

Hundreds of startups and companies like Samsung, Airbus, NEC, and Disney rely on us to build great software products. We can help you too, by enabling you to hire and effortlessly manage expert developers.