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

Clean architecture in Android

  • Upload
    uptech

  • View
    52

  • Download
    1

Embed Size (px)

Citation preview

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

prepared by Halyna Halkina

The plan

● How come we’re all here

● The usual way

● The Clean Architecture way

Why architecture?

How it was before

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

Project structure in a couple of months

Navigating through the project be like...

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

Logic classes: Pros

● UI separation from other application stuff

● Ability to split functionality into several Logic Classes

● A bit cleaner code :)

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

grow as you get more use cases

Clean Architecture to the rescue!

Clean Architecture by Robert Martin

Clean Architecture: Pros and characteristics

● Independent of Frameworks

● Independent of UI

● Independent of Database

● Independent of any external agency

Clean Architecture in Android by Fernando Cejas

Clean Architecture in Android by Fernando Cejas

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)

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

Sample packages structure

Code sample: Data Store Interface

Code Sample: Data Store

Code sample: Use case

Code Sample: Use Case

Code sample: Presenter with a use case

Code Sample: View

Code Sample: View Implementation

Thank you for your attention!

Do you have any questions?