Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clean Architecture & Error Handling
Search
Ahtsham Abbasi
October 24, 2022
Technology
0
130
Clean Architecture & Error Handling
Ahtsham Abbasi
October 24, 2022
Tweet
Share
Other Decks in Technology
See All in Technology
AndroidアプリエンジニアもMCPを触ろう
kgmyshin
2
500
ドキュメント管理の理想と現実
kazuhe
1
280
SnowflakeとDatabricks両方でRAGを構築してみた
kameitomohiro
1
530
Dataverseの検索列について
miyakemito
1
150
Dynamic Reteaming And Self Organization
miholovesq
3
690
AWS全冠芸人が見た世界 ~資格取得より大切なこと~
masakiokuda
6
6.5k
CodePipelineのアクション統合から学ぶAWS CDKの抽象化技術 / codepipeline-actions-cdk-abstraction
gotok365
5
330
Twelve-Factor-Appから学ぶECS設計プラクティス/ECS practice for Twelve-Factor-App
ozawa
3
140
コードや知識を組み込む / Incorporating Codes and Knowledge
ks91
PRO
0
150
白金鉱業Meetup_Vol.18_生成AIはデータサイエンティストを代替するのか?
brainpadpr
3
200
OpenLane-V2ベンチマークと代表的な手法
kzykmyzw
0
130
AIでめっちゃ便利になったけど、結局みんなで学ぶよねっていう話
kakehashi
PRO
1
460
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Code Reviewing Like a Champion
maltzj
523
40k
Done Done
chrislema
184
16k
Become a Pro
speakerdeck
PRO
28
5.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
Build your cross-platform service in a week with App Engine
jlugia
230
18k
How to Ace a Technical Interview
jacobian
276
23k
[RailsConf 2023] Rails as a piece of cake
palkan
54
5.5k
RailsConf 2023
tenderlove
30
1.1k
How GitHub (no longer) Works
holman
314
140k
We Have a Design System, Now What?
morganepeng
52
7.5k
Transcript
Clean Architecture & Error Handling Ahtsham Abbasi Senior Android Developer
@ Mobiquity Consultant @ Rabobank mobiquity
Agenda 1. Clean Architecture 2. Domain Layer 3. Conclusion
#1 Clean Architecture What’s all the fuss about?
None
Why Architecture?
Why Clean Architecture? • Decouples the external components
Why Clean Architecture? • Decouples the external components • Works
with other architectures like MVP, MVC, MVVM
Why Clean Architecture? • Decouples the external components • Works
with other architectures like MVP, MVC, MVVM • Framework independent
What is Clean Architecture?
What is Clean Architecture? Clean code
What is Clean Architecture? Clean code
What is Clean Architecture? Clean code Onion arch. + Hexagonal
arch.
What is Clean Architecture?
Flow of Control
Flow of Control Use Case Controller DB IoC
Number of layers
Layers Entities Use Cases Repositories View Models User Interface Database
Rem ote API
Frontend app • Outer most circle • Notifications code •
Cookies • Displaying content
Backend app • Outer most circle • Database code •
Auth library • 3rd party services
Models Each layer must have its own models.
Dependency Injection Koin, Guice, Spring
#2 Domain Layer Implementation and error handling
Domain Layer
Components of Domain Layer • Use cases
Components of Domain Layer • Use cases • Models
Components of Domain Layer • Use cases • Models •
Interfaces
Use Cases
None
None
None
None
None
Structuring a Use Case • Scope
Structuring a Use Case • Scope • Structure
Structuring a Use Case • Scope • Structure • Inputs
/ Outputs
Outputs • Requirement • Exhaustive output • Easy to learn
• Easy to scale
Outputs • Requirement • Exhaustive output • Easy to learn
• Easy to scale • Different options considered • Kotlin Try • Monadic outputs • Arrow-Kt • Sealed classes
Example
Invocation
Pitfalls to avoid
Pifalls to avoid • Returning nulls
Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data
in outputs
Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data
in outputs • Callbacks
Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data
in outputs • Callbacks • Exceptions
Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data
in outputs • Callbacks • Exceptions • Base classes
Other Layers Entities Use Cases Repositories View Models User Interface
Database Rem ote API • Separate models • Aggregate outputs • Avoid exceptions
#3 Conclusions Learnings so far
Is it a good architecture for me?
It is for you, if you want to.. • Manage
complex and scaling business requirements
It is for you, if you want to.. • Manage
complex and scaling business requirements • Decouple the external components
It is for you, if you want to.. • Manage
complex and scaling business requirements • Decouple the external components • Share business logic across platforms
It is for you, if you want to.. • Manage
complex and scaling business requirements • Decouple the external components • Share business logic across platforms • Increase testability
It is for you, if you want to.. • Manage
complex and scaling business requirements • Decouple the external components • Share business logic across platforms • Increase testability • Have a framework independent architecture
Drawbacks
Drawbacks • Code duplication • Boilerplate code • Learning curve
• Not ideal for smaller projects
Final thoughts
Resources • Clean Architecture Book by Robert C. Martin •
https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html • https://elizarov.medium.com/kotlin-and-exceptions-8062f589d07 • https://pusher.com/tutorials/clean-architecture-introduction/
Thank you! Ahtsham Abbasi ahtabbasi@gmail.com https://www.linkedin.com/in/ahtabbasi/ mobiquity