android clean architecture workshop 3h edition
TRANSCRIPT
![Page 1: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/1.jpg)
#AndroidArch
![Page 2: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/2.jpg)
#AndroidArch
Implementing Clean Architecture in
AndroidJorge D. Ortiz-Fuentes
@jdortiz
![Page 3: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/3.jpg)
A Canonical Examples production
#AndroidArch
![Page 4: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/4.jpg)
#AndroidArch
Agenda★Goals
★Before Clean Architecture
★Clean Architecture Concepts
★ Implementation rules
★Example App: RealProgrammers
★ Implement 1st User Story
★References
![Page 5: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/5.jpg)
#AndroidArch
Full Version: 3d★MVX
• Learn
• Extract MVP
★1st User Story
• Use Case
• Presenter
• View
• Entity Gateway
• Initial connection
★Connectors
• Memory Management
• Reuse
★2nd user story: add
• Navigation: Modal vs Push
• Command pattern
• Immutables
• Observation
★3rd user story: detail
• Identity
• Use case factories
• 2nd use case in the same view
★Other use cases: just logic
★Forward flow synchronization
★Dependency Injection
★Asynchrony
• Async entity gateway
• Other tasks
![Page 6: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/6.jpg)
#AndroidArch
LIVE Online Training★3 days (same weekday 3 continuous weeks)
★10 people max
★Live coding shared via video conference
★Chat running all the time
★Complete repo with many commits and Tests> 95%
★Additional exercises
★Ask as much as you want!
![Page 8: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/8.jpg)
Goals
![Page 9: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/9.jpg)
#AndroidArch
Goals
★Understand the concepts
★ Learn the sources
★ Implement the ideas of the Clean Architecture in a real app
★Grow from here
![Page 10: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/10.jpg)
Looking for volunteer
![Page 11: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/11.jpg)
Warning: Background Ahead!
![Page 12: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/12.jpg)
Before Clean Architecture
![Page 13: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/13.jpg)
#AndroidArch
Before Clean Architecture
★MVC
★MVP
★MVVM
![Page 14: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/14.jpg)
– Martin Fowler
“Different people reading about MVC in different places take different ideas from it and describe these as 'MVC'. If this doesn't cause enough confusion you then get the effect of
misunderstandings of MVC that develop through a system of Chinese whispers.”
![Page 15: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/15.jpg)
#AndroidArch
Tricky question★ If [Model] + [View] + [Controller /
Presenter / View Model] = [TheApp]
★How can Controller != Presenter != View Model?
★Responsibilities matter!
★Other components (patterns) might be involved.
![Page 16: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/16.jpg)
#AndroidArch
The goal★Separation of responsibilities into roles. Is
it? Not historically. Other motivations. Solving problem d’jour.
★Now why?
• Testability
• Reusability
• Extensibility
![Page 17: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/17.jpg)
#AndroidArch
MVC: The early days
★Separated presentation: Model <-> Presentation (= V+C)
★Observer originated from MVC, but observing full object (properties = scalars)
★Variations: Passive model, i.e. model cannot send updates (for example HTTP)
![Page 18: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/18.jpg)
#AndroidArch
Android’s MVC★View
• Only View subclasses
• Show information and handle events to controller
• Fully reusable library of views. Consistent L&F
★Controller
• Listeners+Watchers+Adapters control what’s displayed
• Receive the events and converts them into calls to the model
• Observe the model and update what is displayed on the view
• Implement presentation logic
★Model
• Implements domain knowledge / business logic. Provides data and commands
• Can be observed
• No references to the UI
•Flow synchronization vs Observer synchronization
![Page 19: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/19.jpg)
Apple’s MVC
Ctrlr
ModelView
![Page 20: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/20.jpg)
#AndroidArch
MVC: testability★The views are somebody else's (Google’s)
problem.
★Model is easy to test.
★Controller is huge & has dependencies on the model and on the views => Complex to test.
★Too many levels of abstraction, only a few methods exposed.
★Some stuff in activity that it is usually not tested.
![Page 21: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/21.jpg)
MVP
![Page 22: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/22.jpg)
MVP
Presenter ModelView
Events Operations
Changes Changes
![Page 23: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/23.jpg)
MVVM
![Page 24: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/24.jpg)
MVVM
View Model ModelView
Events & Info Operations
Changes Changes
![Page 25: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/25.jpg)
Clean Architecture Concepts
![Page 26: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/26.jpg)
#AndroidArch
Clean Architecture
★Uncle Bob’s (Robert C. Martin’s) architecture
★Based in Onion, in turn based in hexagonal, DCI and some others
![Page 27: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/27.jpg)
Clean Architecture
View (A/F) Presenter Interactor Entity Gateway
Connector
![Page 28: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/28.jpg)
Persistance FW
View
Netw
ork
Location FW
Presenter
Entity Gateway
Clean Architecture
Interactor
Entity
![Page 29: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/29.jpg)
Implementation Rules
![Page 30: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/30.jpg)
#AndroidArch
Rules★We are going to develop one module at a
time
★ Follow the dependency rules
★YAGNI
★No early optimization applied
★ It is easy to add tests, but no TDD in 3h OK??
![Page 31: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/31.jpg)
Example App: RealProgrammers
![Page 32: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/32.jpg)
#AndroidArch
Features★Add potential candidates (Name, email, and important skills)
★Show list of programmers with relative interview date
★Remove candidates from list
★Edit the data of any candidate
★Contact candidate by email
★Sync between devices
★Universal app (Fragments)
★Eye candy
★Android/Android Wear/Android TV/Google Glasses
★Credits
![Page 33: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/33.jpg)
#AndroidArch
MVP Features★Add potential candidates (Name, email, and important skills)
★Show list of programmers with relative interview date
★Remove candidates from list
★Edit the data of any candidate
★Contact candidate by email
★Sync between devices
★Universal app (Fragments)
★Eye candy
★Android/Android Wear/Android TV/Google Glasses
★Credits
![Page 34: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/34.jpg)
Implementing the 1st User Story
![Page 35: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/35.jpg)
I feel like I could Take On the
World!
![Page 36: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/36.jpg)
#AndroidArch
First User Story
★Show a list of data elements to the user.
![Page 37: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/37.jpg)
Interactor
View (A/F) Presenter Show Programmers
Entity Gateway
![Page 38: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/38.jpg)
#AndroidArch
Interactor
★Grab data from the entity gateway
★Convert it to what is needed to be presented
★Pass the results to the presenter
★Start by defining the interfaces
![Page 39: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/39.jpg)
Presenter
View (A/F) ProgrammersList
Show Programmers
Entity Gateway
![Page 40: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/40.jpg)
#AndroidArch
Presenter
★Direction: only from interactor to view
★Configure the (dumb) view with the data provided to it
★Create the interface for the view (Simplest wins!)
![Page 41: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/41.jpg)
View
Programmers ListActivity
ProgrammersList
Show Programmers
Entity Gateway
![Page 42: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/42.jpg)
#AndroidArch
View
★Combination of Views + Activity
★Make it dumb (passive), but useful
★Tell the presenter about the relevant events
★Keep them decoupled
![Page 43: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/43.jpg)
Presenter
Programmers ListActivity
ProgrammersList
Show Programmers
Entity Gateway
![Page 44: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/44.jpg)
#AndroidArch
Back to the Presenter
★ Implement responses to the user events.
★Use the interactor
★Add presentation logic to the presenter part
![Page 45: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/45.jpg)
#AndroidArch
Presentation Logic
★Date should be relative (“Today”, “1d ago”, “2w ago”)
★That means current date is a dependency that we want to control for tests
★Use lazy instantiation for the current date
![Page 46: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/46.jpg)
Entity Gateway
Programmers ListActivity
ProgrammersList
Show Programmers
Entity Gateway
![Page 47: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/47.jpg)
#AndroidArch
Entity Gateway
★Basic
★Defer the decision of the persistence framework for later.
★ Implement the minimum functionality in a basic object.
★ Implications of the repository pattern.
![Page 48: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/48.jpg)
References
![Page 49: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/49.jpg)
#AndroidArch
References
★http://martinfowler.com/eaaDev/uiArchs.html
★https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
★https://cleancoders.com/episode/clean-code-episode-7/show
![Page 50: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/50.jpg)
Thank you!
![Page 51: Android clean architecture workshop 3h edition](https://reader033.vdocuments.us/reader033/viewer/2022042723/587603a31a28ab4a508b61c7/html5/thumbnails/51.jpg)
@jdortiz #AndroidArch