Top Banner
Clean Architecture in Android well not only in Android, but we did it here prepared by Halyna Halkina
31

Clean architecture in Android

Mar 20, 2017

Download

Software

UPTECH
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Clean architecture in Android

Clean Architecture in Androidwell not only in Android, but we did it here

prepared by Halyna Halkina

Page 2: Clean architecture in Android

The plan

● How come we’re all here

● The usual way

● The Clean Architecture way

Page 3: Clean architecture in Android

Why architecture?

Page 4: Clean architecture in Android

How it was before

Page 5: Clean architecture in Android

The simplest way

Activities and Fragments (and sometimes even Adapters, brr)

contain everything. All the API calls, saving to DB, logic

manipulations are in them

Page 6: Clean architecture in Android
Page 7: Clean architecture in Android
Page 8: Clean architecture in Android

Project structure in a couple of months

Page 9: Clean architecture in Android

Navigating through the project be like...

Page 10: Clean architecture in Android

Let’s move logic somewhere!

Logic doesn’t belong in the UI. We would like to have some

place where we’ll keep it separately from Views, Activities and

Fragments

That’s exactly how we got Managers

Page 11: Clean architecture in Android

Logic classes: Pros

● UI separation from other application stuff

● Ability to split functionality into several Logic Classes

● A bit cleaner code :)

Page 12: Clean architecture in Android
Page 13: Clean architecture in Android

Why bad?Managers (or just collections of random somehow connected logic) tend to grow and

grow as you get more use cases

Page 14: Clean architecture in Android
Page 15: Clean architecture in Android

Clean Architecture to the rescue!

Page 16: Clean architecture in Android

Clean Architecture by Robert Martin

Page 17: Clean architecture in Android

Clean Architecture: Pros and characteristics

● Independent of Frameworks

● Independent of UI

● Independent of Database

● Independent of any external agency

Page 18: Clean architecture in Android

Clean Architecture in Android by Fernando Cejas

Page 19: Clean architecture in Android

Clean Architecture in Android by Fernando Cejas

Page 20: Clean architecture in Android

So what does it all add up to?We ended up with given scheme:

● Presentation layer - Model-View-Presenter

● Domain layer - Use Cases (using both data layer’s Data

Stores and network API)

● Data layer - Data Stores (storing data in the DB and in

memory cache, using API to get/update information)

Page 21: Clean architecture in Android

Sample application structure: modules by Fernando Cejas and packages by us

Page 22: Clean architecture in Android

Sample packages structure

Page 23: Clean architecture in Android

Code sample: Data Store Interface

Page 24: Clean architecture in Android

Code Sample: Data Store

Page 25: Clean architecture in Android

Code sample: Use case

Page 26: Clean architecture in Android

Code Sample: Use Case

Page 27: Clean architecture in Android

Code sample: Presenter with a use case

Page 28: Clean architecture in Android

Code Sample: View

Page 29: Clean architecture in Android

Code Sample: View Implementation

Page 30: Clean architecture in Android

Thank you for your attention!

Do you have any questions?