SlideShare a Scribd company logo
2
Most read
12
Most read
14
Most read
Clean Architecture on Android
Benjamin / 班傑明
A real-world app
Fragment Adapter
AsyncTask
Network API client
AsyncTask
View
View
Data model
Challenge
● Hard to understand/maintain
○ The business logic is mixed in Activity/Fragment/Adapter
○ Loose cohesive, high coupled (低內聚,高耦合)
● Hard to test
○ Cannot fully test the logic in Activity/Fragment/Adapter
○ The UI testing is fragile. (Will build fail if there are content or server-side issues)
○ It costs around 30 minutes to finish our UI testing
○ It’s really frustrating and lose productivity when the tests keep failing (lots of 30+ minutes)
MVP
From: http://www.captechconsulting.com/blogs/a-mvp-approach-to-lifecycle-safe-requests-with-retrofit-20-and-rxjava
MVP - Interfaces
Program to an interface, not an implementation
MVP - View
MVP - View
MVP - Presenter
MVP - Model
● Model? NetworkAPIClient?
● Is MVP an Architecture pattern?
MVC/MVP/MVVM is NOT an Architecture
● MVP is not an architectural pattern, it’s only responsible
for the presentation layer (delivery mechanism)
The Clean Architecture
From: http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
The Clean Architecture (conti.)
From Robert C Martin - Clean Architecture and Design https://www.youtube.com/watch?v=Nsjsiz2A9mg
Interactor - Application specific business rules
● Application specific business rules
● Use cases
● ex: Content aggregation logic for your
app’s landing page, add product to cart, ...
● Regular Java object. No android
framework dependency
Repository - Data access
● Application independent business rules
● Business object / Domain model
● Access data by network, memory cache
and disk cache, has Android framework
dependency
● ex: RestAPI, Preference, disk cache
Boundary
● No direct dependency between
framework and Interactor
● Interactor can be well tested without
framework
MVP - Presentation Layer
● Presenter: Define interfaces for all the UI
interactions [Regular Java object, no
android framework dependency]
The Clean Architecture on Android
Fragment Adapter
Network API client
View
View
Presenter Interactor RepositoryViewModel
DataCache
Response
Model
The Clean Architecture
● Independent of Frameworks
● Testable
● Allow major decisions(UI, framework, databases) to be
deferred
Android application architecture: Get ready for the next
billion! - Google I/O 2016
From https://www.youtube.com/watch?v=70WqJxymPr8
Testing
● Presentation layer
○ Expresso
● Domain layer (Use case/Interactor)
○ JUnit + mockito
● Data layer
○ Roboletric + JUnit + mockito
Prod
build flavor
Expresso + Mockito
Fragment AdapterView
View
Presenter
InjectionInteractor
Repository
Expresso + Mockito (conti.)
Mock
build flavor
Fragment AdapterView
View
Presenter
InjectionMockInteractor
Repository
Expresso + Mockito (conti.)
Reference
● Robert C Martin - Clean Architecture and Design https://www.youtube.com/watch?v=Nsjsiz2A9mg
● Architecting Android…The clean way? http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/
● Android Application Architecture. Our journey from standard Activities and AsyncTasks to a modern MVP-based architecture
powered by RxJava. https://labs.ribot.co.uk/android-application-architecture-8b6e34acda65#.zexgfy5tt
● Android Testing (Android Dev Summit 2015) https://www.youtube.com/watch?v=vdasFFfXKOY
● Android Testing Codelab https://codelabs.developers.google.com/codelabs/android-testing/index.html#0
● Advanced Android Espresso http://chiuki.github.io/advanced-android-espresso/#/

More Related Content

PDF
Clean Architecture
PPTX
SOLID principles
PDF
Hexagonal architecture - message-oriented software design
PPT
Spring Core
PDF
Introducing Clean Architecture
PDF
SOLID Design Principles applied in Java
PPTX
Clean architecture
PPTX
Vertical Slicing Architectures
Clean Architecture
SOLID principles
Hexagonal architecture - message-oriented software design
Spring Core
Introducing Clean Architecture
SOLID Design Principles applied in Java
Clean architecture
Vertical Slicing Architectures

What's hot (20)

PPT
SOLID Design Principles
PPSX
SOLID Principles and The Clean Architecture
PPTX
Clean Architecture
PPTX
Clean architecture
PDF
Clean Architecture
PDF
Clean coding-practices
PPTX
Solid principles
PPTX
Spring Boot Tutorial
PDF
Real Life Clean Architecture
PPTX
Java database connectivity with MySql
PDF
2012 the clean architecture by Uncle bob
PDF
Clean pragmatic architecture @ devflix
ODP
Spring User Guide
PPTX
Spring Security 5
PDF
Hexagonal architecture
PPTX
Clean architecture
PPTX
Introduction to JSX
PPTX
What is component in reactjs
PPTX
Refactoring Applications using SOLID Principles
SOLID Design Principles
SOLID Principles and The Clean Architecture
Clean Architecture
Clean architecture
Clean Architecture
Clean coding-practices
Solid principles
Spring Boot Tutorial
Real Life Clean Architecture
Java database connectivity with MySql
2012 the clean architecture by Uncle bob
Clean pragmatic architecture @ devflix
Spring User Guide
Spring Security 5
Hexagonal architecture
Clean architecture
Introduction to JSX
What is component in reactjs
Refactoring Applications using SOLID Principles
Ad

Viewers also liked (20)

PDF
Android Clean Architecture for Dummies
PDF
A Separation of Concerns: Clean Architecture on Android
PDF
Clean architecture: Android
PPT
Design pattern in android
PDF
Android cleanarchitecture
ODP
Androd rest client architecture
PDF
MVP Clean Architecture
PPTX
Lightning Talk - Clean Architecture and Design
PPTX
Clean code in Jupyter notebooks
PDF
Infinum Android Talks #12 - MVP design pattern for Android Apps
PDF
Android Architecture MVP Pattern
PDF
Designing a participatory sensing game with children
ODP
Android advanced client architecture
PDF
Clean Architecture in Android. UPTech TechTalk
PDF
To Protect & To Serve
PPT
Choice Paralysis
PDF
Android clean architecture workshop 3h edition
PDF
About Flux
PDF
Intro to RxJava/RxAndroid - GDG Munich Android
PDF
React.js and Flux in details
Android Clean Architecture for Dummies
A Separation of Concerns: Clean Architecture on Android
Clean architecture: Android
Design pattern in android
Android cleanarchitecture
Androd rest client architecture
MVP Clean Architecture
Lightning Talk - Clean Architecture and Design
Clean code in Jupyter notebooks
Infinum Android Talks #12 - MVP design pattern for Android Apps
Android Architecture MVP Pattern
Designing a participatory sensing game with children
Android advanced client architecture
Clean Architecture in Android. UPTech TechTalk
To Protect & To Serve
Choice Paralysis
Android clean architecture workshop 3h edition
About Flux
Intro to RxJava/RxAndroid - GDG Munich Android
React.js and Flux in details
Ad

Similar to Clean architecture on android (20)

PDF
Jorge D. Ortiz Fuentes "Hands on Implementation of Clean Architecture for And...
PPTX
Architecting modern Android apps
PDF
Clean Architecture @ Taxibeat
PDF
Clean Architecture
PPTX
Android Architectures
PDF
Clean Architecture
PDF
Five android architecture
PDF
Android meetup
PDF
Clean Architecture on Android
PPTX
Android DesignArchitectures.pptx
PDF
Android Clean Architecture with Kotlin and RxJava
PDF
My way to clean android (EN) - Android day salamanca edition
PDF
Testable Android Architecture
PDF
Session dotNed Saturday 28 januari 2017
PDF
Android architecture blueprints overview
PDF
Android DevConference - Android Clean Architecture
PDF
Create first android app with MVVM Architecture
PDF
A mysterious journey to MVP world - Viber Android Meetup 2018
PDF
Android App Architecture
PDF
My way to clean android - Android day salamanca edition
Jorge D. Ortiz Fuentes "Hands on Implementation of Clean Architecture for And...
Architecting modern Android apps
Clean Architecture @ Taxibeat
Clean Architecture
Android Architectures
Clean Architecture
Five android architecture
Android meetup
Clean Architecture on Android
Android DesignArchitectures.pptx
Android Clean Architecture with Kotlin and RxJava
My way to clean android (EN) - Android day salamanca edition
Testable Android Architecture
Session dotNed Saturday 28 januari 2017
Android architecture blueprints overview
Android DevConference - Android Clean Architecture
Create first android app with MVVM Architecture
A mysterious journey to MVP world - Viber Android Meetup 2018
Android App Architecture
My way to clean android - Android day salamanca edition

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
System and Network Administration Chapter 2
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Introduction to Artificial Intelligence
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Transform Your Business with a Software ERP System
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
System and Network Administraation Chapter 3
PDF
Nekopoi APK 2025 free lastest update
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
wealthsignaloriginal-com-DS-text-... (1).pdf
Design an Analysis of Algorithms II-SECS-1021-03
Design an Analysis of Algorithms I-SECS-1021-03
System and Network Administration Chapter 2
Understanding Forklifts - TECH EHS Solution
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Odoo Companies in India – Driving Business Transformation.pdf
Introduction to Artificial Intelligence
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Migrate SBCGlobal Email to Yahoo Easily
2025 Textile ERP Trends: SAP, Odoo & Oracle
How to Choose the Right IT Partner for Your Business in Malaysia
Transform Your Business with a Software ERP System
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
System and Network Administraation Chapter 3
Nekopoi APK 2025 free lastest update
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

Clean architecture on android

  • 1. Clean Architecture on Android Benjamin / 班傑明
  • 2. A real-world app Fragment Adapter AsyncTask Network API client AsyncTask View View Data model
  • 3. Challenge ● Hard to understand/maintain ○ The business logic is mixed in Activity/Fragment/Adapter ○ Loose cohesive, high coupled (低內聚,高耦合) ● Hard to test ○ Cannot fully test the logic in Activity/Fragment/Adapter ○ The UI testing is fragile. (Will build fail if there are content or server-side issues) ○ It costs around 30 minutes to finish our UI testing ○ It’s really frustrating and lose productivity when the tests keep failing (lots of 30+ minutes)
  • 5. MVP - Interfaces Program to an interface, not an implementation
  • 9. MVP - Model ● Model? NetworkAPIClient? ● Is MVP an Architecture pattern?
  • 10. MVC/MVP/MVVM is NOT an Architecture ● MVP is not an architectural pattern, it’s only responsible for the presentation layer (delivery mechanism)
  • 11. The Clean Architecture From: http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
  • 12. The Clean Architecture (conti.) From Robert C Martin - Clean Architecture and Design https://www.youtube.com/watch?v=Nsjsiz2A9mg
  • 13. Interactor - Application specific business rules ● Application specific business rules ● Use cases ● ex: Content aggregation logic for your app’s landing page, add product to cart, ... ● Regular Java object. No android framework dependency
  • 14. Repository - Data access ● Application independent business rules ● Business object / Domain model ● Access data by network, memory cache and disk cache, has Android framework dependency ● ex: RestAPI, Preference, disk cache
  • 15. Boundary ● No direct dependency between framework and Interactor ● Interactor can be well tested without framework
  • 16. MVP - Presentation Layer ● Presenter: Define interfaces for all the UI interactions [Regular Java object, no android framework dependency]
  • 17. The Clean Architecture on Android Fragment Adapter Network API client View View Presenter Interactor RepositoryViewModel DataCache Response Model
  • 18. The Clean Architecture ● Independent of Frameworks ● Testable ● Allow major decisions(UI, framework, databases) to be deferred
  • 19. Android application architecture: Get ready for the next billion! - Google I/O 2016 From https://www.youtube.com/watch?v=70WqJxymPr8
  • 20. Testing ● Presentation layer ○ Expresso ● Domain layer (Use case/Interactor) ○ JUnit + mockito ● Data layer ○ Roboletric + JUnit + mockito
  • 21. Prod build flavor Expresso + Mockito Fragment AdapterView View Presenter InjectionInteractor Repository
  • 22. Expresso + Mockito (conti.) Mock build flavor Fragment AdapterView View Presenter InjectionMockInteractor Repository
  • 23. Expresso + Mockito (conti.)
  • 24. Reference ● Robert C Martin - Clean Architecture and Design https://www.youtube.com/watch?v=Nsjsiz2A9mg ● Architecting Android…The clean way? http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/ ● Android Application Architecture. Our journey from standard Activities and AsyncTasks to a modern MVP-based architecture powered by RxJava. https://labs.ribot.co.uk/android-application-architecture-8b6e34acda65#.zexgfy5tt ● Android Testing (Android Dev Summit 2015) https://www.youtube.com/watch?v=vdasFFfXKOY ● Android Testing Codelab https://codelabs.developers.google.com/codelabs/android-testing/index.html#0 ● Advanced Android Espresso http://chiuki.github.io/advanced-android-espresso/#/

Editor's Notes

  • #5: From http://www.captechconsulting.com/blogs/a-mvp-approach-to-lifecycle-safe-requests-with-retrofit-20-and-rxjava
  • #12: From http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
  • #18: Presenter: define interfaces for all the UI interactions [Regular Java object, no android framework dependency] Inteactor: Business logic [Regular Java object, no android framework dependency] Repository: Access data by network, memory cache and disk cache [Android framework dependency]
  • #20: From http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html