DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. The Cognitive Appeal of the Clean and the New Android Architectures

The Cognitive Appeal of the Clean and the New Android Architectures

A fundamental change is about to change how Android works at its core. But why should you care? And, why is this a good thing? Let's take a look.

Pronab Pal user avatar by
Pronab Pal
·
Sep. 14, 18 · Analysis
Like (4)
Save
Tweet
Share
4.85K Views

Join the DZone community and get the full member experience.

Join For Free

Android's new architecture component is now official and solidified. There is no doubt that the architecture components, like View Models and LiveData, will make the life of newcomers in the Android development world much more painless.

But to a seasoned developer, the question will inevitably arise about how and where the new architecture components sit with the concepts of clean architecture, as promoted by Uncle Bob.

You may ask why should we worry about clean architecture? The answer is simple — clean architecture is based on how humans relate to the software development cycle, meaning that it comes down to a simple and single principle of "Separation Of Concern." Clean architecture is not limited to a particular platform solution, as are the concepts of Android Lifecycle and the solutions around it.

With that question in mind, I wanted to see how one of the recent samples from Google, using their architecture components, fits with the fundamental concept of clean architecture. The core concept of clean architecture is summarized in the picture and is very familiar to anyone aware of clean architecture as proposed here:

Core Principle in the Clean Architecture

"Nothing in an inner circle can know anything at all about something in an outer circle. In particular, the name of something declared in an outer circle must not be mentioned by the code in an inner circle. That includes functions, classes, variables, or any other named software entity."

The sample I took is the "Room with a View" sample from Google code lab.

Although there are a number of implementations of clean architecture using approaches, like MVP, MVVM, etc., which gives a viable solution on the Android space, my question here is, if we can maintain the core concept of clean architecture namely : "the name of something declared in an outer circle must not be mentioned by the code in an inner circle" without bringing any framework, by just using the Android Architecture Components.

The "Room With A View" is a simple application that lists the words in a database and allows you to add new words.

There are eight classes in the app:

  1.  MainActivity 
  2.  NewWordActivity 
  3.  Word 
  4.  WordDao 
  5.  WordListAdapter 
  6.  WordRepository 
  7.  WordRoomDatabase 
  8.  WordViewModel 

Without much difficulty, I could achieve the desired organization with about 90 percent success:

A Few Concerns

The LiveData as an element does not appear anywhere in the organization. While it is true that LiveData is a facility/mechanism, it is not an entity in the policy sense.

The clean architecture says, "The outer circles are mechanisms. The inner circles are policies." On that basis, it puts the DB at the very outer most layer. However, I could not put the DB in the outer circle without breaking the core principle.

I understand this is more of a sign of how DB in the current technology has become more of a wide al encompassing concept rather than an implementation detail.

The only other concern I had was with the sense of the separation of concern detail when the ViewModel  sits in the UI controller, whereas the ListAdapter is supposed to take care of data that is on display. The adapter is capable of observing the view model of any change. If we do that, then we can say the adapter pretty much decides what data to display from the repository side. UI is responsible for maintaining the correct UI look and feel of components. With that in mind, I moved the view models in the adapter, which exposes an extra method "insert (..)" to the UI. The modified code is here: Room for A ViewModel.

By doing that, I get a more comfortable picture of the clean architecture circles where the LiveData is an internal tool for the repository to use in its favor:

Conclusion

Android clean architecture is a goal that can be achieved without a great deal of framework, as long we focus on the cognitive separation of concern, along with the testing facility, which is becoming much more language-driven as they are in Kotlin, without bothering about the nature of the tool and facility. We can always adhere to the principle: "In general, the further in you go, the higher level the software becomes." Higher level simply means more encompassing, like the DB implementation is nowadays. We do not care anymore what kind of DB it is, as long as it maintains the exposed interfaces intact. Thanks to the energy in open source, we can afford to see today's tools through a cognitive lens rather than tying our hands and minds to it. This, in turn, makes open source move faster as well.

Architecture Android (robot)

Published at DZone with permission of Pronab Pal, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Path From APIs to Containers
  • REST vs. Messaging for Microservices
  • HTTP vs Messaging for Microservices Communications
  • Spring Boot, Quarkus, or Micronaut?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: