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)
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
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/#/
Notas do Editor
From
http://www.captechconsulting.com/blogs/a-mvp-approach-to-lifecycle-safe-requests-with-retrofit-20-and-rxjava
From
http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
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]
From
http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html