Slide 1

Slide 1 text

Clean Architecture & Error Handling Ahtsham Abbasi Senior Android Developer @ Mobiquity Consultant @ Rabobank mobiquity

Slide 2

Slide 2 text

Agenda 1. Clean Architecture 2. Domain Layer 3. Conclusion

Slide 3

Slide 3 text

#1 Clean Architecture What’s all the fuss about?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Why Architecture?

Slide 6

Slide 6 text

Why Clean Architecture? • Decouples the external components

Slide 7

Slide 7 text

Why Clean Architecture? • Decouples the external components • Works with other architectures like MVP, MVC, MVVM

Slide 8

Slide 8 text

Why Clean Architecture? • Decouples the external components • Works with other architectures like MVP, MVC, MVVM • Framework independent

Slide 9

Slide 9 text

What is Clean Architecture?

Slide 10

Slide 10 text

What is Clean Architecture? Clean code

Slide 11

Slide 11 text

What is Clean Architecture? Clean code

Slide 12

Slide 12 text

What is Clean Architecture? Clean code Onion arch. + Hexagonal arch.

Slide 13

Slide 13 text

What is Clean Architecture?

Slide 14

Slide 14 text

Flow of Control

Slide 15

Slide 15 text

Flow of Control Use Case Controller DB IoC

Slide 16

Slide 16 text

Number of layers

Slide 17

Slide 17 text

Layers Entities Use Cases Repositories View Models User Interface Database Rem ote API

Slide 18

Slide 18 text

Frontend app • Outer most circle • Notifications code • Cookies • Displaying content

Slide 19

Slide 19 text

Backend app • Outer most circle • Database code • Auth library • 3rd party services

Slide 20

Slide 20 text

Models Each layer must have its own models.

Slide 21

Slide 21 text

Dependency Injection Koin, Guice, Spring

Slide 22

Slide 22 text

#2 Domain Layer Implementation and error handling

Slide 23

Slide 23 text

Domain Layer

Slide 24

Slide 24 text

Components of Domain Layer • Use cases

Slide 25

Slide 25 text

Components of Domain Layer • Use cases • Models

Slide 26

Slide 26 text

Components of Domain Layer • Use cases • Models • Interfaces

Slide 27

Slide 27 text

Use Cases

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Structuring a Use Case • Scope

Slide 34

Slide 34 text

Structuring a Use Case • Scope • Structure

Slide 35

Slide 35 text

Structuring a Use Case • Scope • Structure • Inputs / Outputs

Slide 36

Slide 36 text

Outputs • Requirement • Exhaustive output • Easy to learn • Easy to scale

Slide 37

Slide 37 text

Outputs • Requirement • Exhaustive output • Easy to learn • Easy to scale • Different options considered • Kotlin Try • Monadic outputs • Arrow-Kt • Sealed classes

Slide 38

Slide 38 text

Example

Slide 39

Slide 39 text

Invocation

Slide 40

Slide 40 text

Pitfalls to avoid

Slide 41

Slide 41 text

Pifalls to avoid • Returning nulls

Slide 42

Slide 42 text

Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data in outputs

Slide 43

Slide 43 text

Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data in outputs • Callbacks

Slide 44

Slide 44 text

Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data in outputs • Callbacks • Exceptions

Slide 45

Slide 45 text

Pifalls to avoid • Returning nulls • Wrapping non-exhaustible data in outputs • Callbacks • Exceptions • Base classes

Slide 46

Slide 46 text

Other Layers Entities Use Cases Repositories View Models User Interface Database Rem ote API • Separate models • Aggregate outputs • Avoid exceptions

Slide 47

Slide 47 text

#3 Conclusions Learnings so far

Slide 48

Slide 48 text

Is it a good architecture for me?

Slide 49

Slide 49 text

It is for you, if you want to.. • Manage complex and scaling business requirements

Slide 50

Slide 50 text

It is for you, if you want to.. • Manage complex and scaling business requirements • Decouple the external components

Slide 51

Slide 51 text

It is for you, if you want to.. • Manage complex and scaling business requirements • Decouple the external components • Share business logic across platforms

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Drawbacks

Slide 55

Slide 55 text

Drawbacks • Code duplication • Boilerplate code • Learning curve • Not ideal for smaller projects

Slide 56

Slide 56 text

Final thoughts

Slide 57

Slide 57 text

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/

Slide 58

Slide 58 text

Thank you! Ahtsham Abbasi [email protected] https://www.linkedin.com/in/ahtabbasi/ mobiquity