a separation of concerns - arq group · a separation of concerns kamal kamal mohamed android...
TRANSCRIPT
![Page 1: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/1.jpg)
A Separation of Concerns
Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile
Ryan Hodgman Official Despiser of Utils Classes @ Outware Mobile
Clean Architecture on Android
18/09/2015 - YOW Connected 2015
![Page 2: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/2.jpg)
Why are we here?
To share with you our journey in applying Clean Architecture to an
Android project
...and get some valuable feedback
![Page 3: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/3.jpg)
Premise
Our own interpretation
Under development
Not a silver bullet
Iterating on it on a day to day basis
Best suited for medium-big projects
Multiple possible implementations
![Page 4: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/4.jpg)
![Page 5: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/5.jpg)
What are our goals as developers?
Easy to refactor on volatile projects
Maintainable
![Page 6: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/6.jpg)
What are our goals as developers?
Easy to refactor on volatile projects
Maintainable
Be confident that the code is reliable
Testable
![Page 7: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/7.jpg)
What are our goals as developers?
Easy to refactor on volatile projects
Maintainable
Be confident that the code is reliable
Testable
Can increase scope without requiring a rework
Scalable
![Page 8: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/8.jpg)
What are our goals as developers?
Easy to refactor on volatile projects
Maintainable
Be confident that the code is reliable
Testable
Reduce the difficulty of future development efforts
ReadableCan increase scope without requiring a rework
Scalable
![Page 9: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/9.jpg)
Introduction to Clean
![Page 10: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/10.jpg)
What is Clean Architecture?
![Page 11: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/11.jpg)
Robert Martin’s original depiction of Clean Architecture https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
![Page 12: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/12.jpg)
The Dependency Rule
Source code dependencies can only point inwards
![Page 13: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/13.jpg)
How many layers?
(The answer is three)
![Page 14: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/14.jpg)
Separation of Concerns
Presentation LogicDefines how to display visual information to the user
Examples:
● Organize screen layout
● Format text
● Enable user input
![Page 15: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/15.jpg)
Separation of Concerns
Business LogicImplements the business requirements of the application
Examples:
● Verify user authorization
● Choose data to be displayed
● Determine if additional user input is required
![Page 16: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/16.jpg)
Separation of Concerns
Data LogicStores and retrieves data to achieve the business requirements
Examples:
● Make an API call
● Query a local database
● Access the local filesystem
![Page 17: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/17.jpg)
Architectural Diagram
![Page 18: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/18.jpg)
Image Source: Lucasfilm Ltd. All Rights Reserved
Architectural Diagram
![Page 19: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/19.jpg)
Domain Layer
![Page 20: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/20.jpg)
Domain Layer
![Page 21: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/21.jpg)
Entity
Represents a business object that concerns the applicationLeast likely to change when shifting requirements
![Page 22: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/22.jpg)
Responsibilities
Entity
Represents a business object that concerns the applicationLeast likely to change when shifting requirements
● Model the relationships with real-world objects / concepts
● Encapsulate the properties required by the application’s business logic
![Page 23: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/23.jpg)
Responsibilities Interactions
Entity
Represents a business object that concerns the applicationLeast likely to change when shifting requirements
● Model the relationships with real-world objects / concepts
● Encapsulate the properties required by the application’s business logic
● May be used directly by all layers of the application
● Likely that they may be mapped from data sources or to presentable view models
![Page 24: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/24.jpg)
Entity
![Page 25: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/25.jpg)
Entity
Properties
![Page 26: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/26.jpg)
Entity
Entity-specific logic
![Page 27: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/27.jpg)
Use Case
Contains the business logic related to a specific use caseCan be run and canceled
![Page 28: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/28.jpg)
Responsibilities
Use Case
Contains the business logic related to a specific use caseCan be run and canceled
● Execute a piece of business logic
● Define a Callback to provide results
● Inform the Callback of the result
● Interact with the data layer
![Page 29: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/29.jpg)
Responsibilities Interactions
Use Case
Contains the business logic related to a specific use caseCan be run and canceled
● Execute a piece of business logic
● Define a Callback to provide results
● Inform the Callback of the result
● Interact with the data layer
Use Case
Use Case Callback
Repository Callback
NotifiesUses
Repository
Implements
![Page 30: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/30.jpg)
Use Case
![Page 31: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/31.jpg)
Use Case
One or more Repository objects
![Page 32: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/32.jpg)
Use Case
May be run and cancelled
![Page 33: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/33.jpg)
Use Case
Contains business logic
![Page 34: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/34.jpg)
Use Case
Defines interactions
![Page 35: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/35.jpg)
Repository
Asynchronous interface to abstract data access to a specific set of data from the data layer
![Page 36: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/36.jpg)
Responsibilities
Repository
Asynchronous interface to abstract data access to a specific set of data from the data layer
● Provide methods to store and retrieve data of a specific type
● Define Callback interfaces to return the results of each operation
![Page 37: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/37.jpg)
Responsibilities Interactions
Repository
Asynchronous interface to abstract data access to a specific set of data from the data layer
● Provide methods to store and retrieve data of a specific type
● Define Callback interfaces to return the results of each operation
Repository
Data ManagerUse Case
ImplementsUses
![Page 38: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/38.jpg)
Repository
![Page 39: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/39.jpg)
Repository
Asynchronous
![Page 40: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/40.jpg)
Repository
Callback definition
![Page 41: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/41.jpg)
A Brief Note on Test-Driven-Development
![Page 42: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/42.jpg)
Presentation Layer
![Page 43: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/43.jpg)
Presentation Layer
![Page 44: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/44.jpg)
Model-View-Presenter
Presenter
View Surface Activity
Presentation
Domain
Fragment
View
Implements
Uses
Uses
Uses
![Page 45: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/45.jpg)
Presenter
Implements presentation logic by directing UI changes and handling user input
![Page 46: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/46.jpg)
Responsibilities
Presenter
Implements presentation logic by directing UI changes and handling user input
● Direct UI changes
● Handle user triggered UI events
● Create and trigger Use Case objects
● Define a View Surface interface
![Page 47: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/47.jpg)
Responsibilities Interactions
Presenter
Implements presentation logic by directing UI changes and handling user input
● Direct UI changes
● Handle user triggered UI events
● Create and trigger Use Case objects
● Define a View Surface interface
Presenter
View SurfaceUse Case Callback
UsesTriggers
Use Case
Implements
![Page 48: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/48.jpg)
Presenter
![Page 49: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/49.jpg)
Presenter
Systems Surfaces and Use Cases
![Page 50: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/50.jpg)
Presenter
Lifecycle events
![Page 51: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/51.jpg)
Presenter
UI event management
![Page 52: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/52.jpg)
View Surface
Abstracts away the implementation of the UI logic, and is typically implemented by a View, Activity or Fragment
![Page 53: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/53.jpg)
Responsibilities
View Surface
Abstracts away the implementation of the UI logic, and is typically implemented by a View, Activity or Fragment
● Screen layout
● Animations / transitions
● Propagate UI events to the Presenter
● Navigation
![Page 54: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/54.jpg)
Responsibilities Interactions
View Surface
Abstracts away the implementation of the UI logic, and is typically implemented by a View, Activity or Fragment
● Screen layout
● Animations / transitions
● Propagate UI events to the Presenter
● Navigation
Activity
PresenterPresenterView Surface
InformsImplements
![Page 55: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/55.jpg)
View Surface
![Page 56: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/56.jpg)
View Surface
Navigation
![Page 57: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/57.jpg)
View Surface
UI information
![Page 58: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/58.jpg)
View Surface
UI state
![Page 59: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/59.jpg)
System Surface
Abstracts away the implementation of various system functionalities
![Page 60: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/60.jpg)
Responsibilities
System Surface
Abstracts away the implementation of various system functionalities
● Provide functionality specific to the OS / device
● Gracefully fail in the event of missing functionality
![Page 61: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/61.jpg)
Responsibilities Interactions
System Surface
Abstracts away the implementation of various system functionalities
● Provide functionality specific to the OS / device
● Gracefully fail in the event of missing functionality
System Surface
Used by
Presenter
![Page 62: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/62.jpg)
System Surface
Android System Dependencies
Abstracted System Specifics
![Page 63: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/63.jpg)
System Surface
Android system dependencies
![Page 64: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/64.jpg)
System Surface
System-specific implementation
![Page 65: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/65.jpg)
Data Layer
![Page 66: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/66.jpg)
Data Layer
![Page 67: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/67.jpg)
Data Manager
Implements a single Repository interface to handle all the data sources required for a specific set of data
![Page 68: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/68.jpg)
Responsibilities
Data Manager
Implements a single Repository interface to handle all the data sources required for a specific set of data
● Provide access to a specific set of data
● Make request on a data source in the form of a Client
● Handle a cache when required
![Page 69: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/69.jpg)
Responsibilities Interactions
Data Manager
Implements a single Repository interface to handle all the data sources required for a specific set of data
● Provide access to a specific set of data
● Make request on a data source in the form of a Client
● Handle a cache when required
Data Manager
Repository CallbackRepository
NotifiesImplements
Client
Uses
![Page 70: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/70.jpg)
Client
Encapsulates a particular source of data and exposes an abstracted interface to the Data Managers
![Page 71: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/71.jpg)
Responsibilities
Client
Encapsulates a particular source of data and exposes an abstracted interface to the Data Managers
● Make Database queries
● Manage an API connection
● Access Local Storage
● Map data results to domain Entities
![Page 72: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/72.jpg)
Responsibilities Interactions
Client
Encapsulates a particular source of data and exposes an abstracted interface to the Data Managers
● Make Database queries
● Manage an API connection
● Access Local Storage
● Map data results to domain Entities
Client
Data Manager
Used by
Mapper
Uses
Handles
Data Source
![Page 73: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/73.jpg)
Mapper
Converts a data object (API or DB response) to a domain Entity
![Page 74: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/74.jpg)
Responsibilities
Mapper
Converts a data object (API or DB response) to a domain Entity
● Transform data into domain-convenient Entities
![Page 75: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/75.jpg)
Responsibilities Interactions
Mapper
Converts a data object (API or DB response) to a domain Entity
● Transform data into domain-convenient Entities
Mapper
Data Object
Entity
![Page 76: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/76.jpg)
Conclusions
![Page 77: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/77.jpg)
Pros
Workflow improvements
Code readability
Testability
No more 1000+ line Activity classes
Isolated business logic
Possibility to work on separate layers in parallel
![Page 78: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/78.jpg)
Cons
Hierarchy implementation
Developer onboarding
Interfaces
Increased ramp-up time for new developers
Interfaces, interfaces, ...
Implementing a feature requires working across all of the layers
![Page 79: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/79.jpg)
Further thoughts
Dagger 2! Can help a lot with keeping the layers clean
Dependency injection
![Page 80: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/80.jpg)
Further thoughts
Dagger 2! Can help a lot with keeping the layers clean
Dependency injection
Where should we split tasks onto a worker thread?
Thread management
![Page 81: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/81.jpg)
Further thoughts
Dagger 2! Can help a lot with keeping the layers clean
Dependency injection
Where should we split tasks onto a worker thread?
Thread management
RxJava! Helps to reduce callbacks and make flows clearer
Functional programming
![Page 82: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/82.jpg)
Further thoughts
Dagger 2! Can help a lot with keeping the layers clean
Dependency injection
Where should we split tasks onto a worker thread?
Thread management
RxJava! Helps to reduce callbacks and make flows clearer
Functional programming
May be useful to model a stateful user flow through the application
User narratives
![Page 83: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/83.jpg)
Next thing you can do!
Consider the separation between data, domain, and presentation logic in one of your projects
![Page 84: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/84.jpg)
References
The Clean Architecture [Uncle Bob]https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
Architecting Android…The clean way? [Fernando Cejas]http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/
Sample Project [Ryan and Kamal]https://github.com/outware-mobile/android-clean-architecture
![Page 85: A Separation of Concerns - Arq Group · A Separation of Concerns Kamal Kamal Mohamed Android Developer, //TODO Find Better Title @ Outware Mobile Ryan Hodgman Official Despiser of](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5ee16fcead6a402d666c5255/html5/thumbnails/85.jpg)
Contact details
Kamal Kamal Mohamed
Ryan Hodgman