Case Study: Login

Chuck Greb
Android Testing
Published in
2 min readSep 17, 2017

Clean architecture is not a one-size-fits-all solution.

It’s not even a single solution, but rather a collection of principles and patterns that can be applied to organize your code and enable testing.

Clean architecture principles (an incomplete list)

  • Forms and controls
  • Separated presentation
  • Passive view
  • Model-View-Controller (MVC)
  • Model-View-Presenter (MVP)
  • Model-View-ViewModel (MVVM)
  • Model-View-Intent (MVI)
  • The Clean Architecture (Uncle Bob)
  • Observer pattern
  • Repository pattern
  • Domain model
  • Data binding
  • Dependency Inversion Principle
  • Inversion of Control
  • State synchronization
  • Dependency injection
  • Testing

These concepts are not unique to Android. Most have been around longer than the platform itself. The challenge for us as Android developers is when and how to best apply them.

Many of these concepts can be used alone or in conjunction with each other. For example, using dependency injection to provide a repository to your presentation layer.

However it is important to not try jamming all of these tools into every application for this will lead to a cluttered codebase that is anything but clean.

Which principles and patterns you should use really depends on the individual application. That’s why I think its useful to look at case studies.

By evaluating various case studies you can see how the same principle or pattern can (or can’t) be applied to different types of applications.

Login Case Study

Login presents a common combination of problems including accepting user input, comparing it against some remote data store, and updating the UI based on the result.

Using Android Studio’s built-in templates we can generate the code for a basic login activity. What we get is a monolithic ~300 line activity that handles all facets of login including input validation, presentation logic, as well as a simulated network call wrapped in an AsyncTask.

And that is in Kotlin. I’m pretty sure the Java version would be over 1,000 lines of code but you can check for yourself.

I’ll spare you the nitty-gritty details for now but you can check out the full source code here.

In the next series of posts we will explore how we can apply some of the classic principles and patterns of clean architecture to the login use case.

Stay tuned!

This post is part of a series on clean architecture that explores how classic software design principles can be applied to modern Android development.

If you found this article helpful, please give it some applause 👏 to help others find it. Feel free to leave a comment below.

--

--

Chuck Greb
Android Testing

Mission-driven engineering leader. Community organizer. Digital minimalist.