half way to clean architecture - dmytro voronkevych - droidcon berlin

127
HALF WAY TO CLEAN ARCHITECTURE

Upload: badoo

Post on 14-Apr-2017

176 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

HALF WAY TO CLEAN ARCHITECTURE

Page 2: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 3: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 4: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 5: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 6: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BADOO

Page 7: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BADOO

• 100K lines

Page 8: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BADOO

• 100K lines

• 185 Activities

Page 9: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BADOO

• 100K lines

• 185 Activities

• 23 Services

Page 10: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BADOO

• 100K lines

• 185 Activities

• 23 Services

• 4 Whitelabels

Page 11: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BADOO

• 100K lines

• 185 Activities

• 23 Services

• 4 Whitelabels

• 4 Applications

Page 12: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS

Page 13: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

Page 14: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 15: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

EVENT BUS

Page 16: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 17: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 18: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 19: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 20: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS

Page 21: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS

Page 22: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

ACTIVITY

Page 23: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

ACTIVITY

Page 24: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

ACTIVITY

Page 25: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 26: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 27: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

NETWORK

CACHE

ACTIVITY

EVENT BUS SERVICE

GLOBAL LISTENER

Page 28: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

— Decomposition rule? ;)

DIVIDE AND CONQUER

Page 29: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 30: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

HelperContract

Controller

Facade

Provider

Delegate

Wrapper

PresenterBuilder

Factory

Cache

Handler Task

View

Strategy

Adapter

Loader

Page 31: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

STANDARDISE

Page 32: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

CLEAN ARCHITECTURE

Page 33: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

Page 34: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

Page 35: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

Page 36: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

package layer3

import layer1 import layer2

Page 37: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

package layer3

import layer1 import layer2

MODEL 1

Page 38: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

package layer3

import layer1 import layer2

MODEL 1

MODEL 2

Page 39: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

package layer3

import layer1 import layer2

MODEL 1

MODEL 2

MODEL 3

Page 40: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

package layer3

import layer1 import layer2

MODEL 1

MODEL 2

MODEL 3

PRESENTATION

Page 41: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

package layer3

import layer1 import layer2

MODEL 1

MODEL 2

MODEL 3

PRESENTATION

DOMAIN

Page 42: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

package layer1

import layer2 import layer3

package layer2

import layer1 import layer3

package layer3

import layer1 import layer2

MODEL 1

MODEL 2

MODEL 3

PRESENTATION

DOMAIN

DATA

Page 43: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 44: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

Farm Layer Transportation Layer Consumer Layer

Page 45: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

Farm Layer Transportation Layer Consumer Layer

Page 46: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

Farm Layer Transportation Layer Consumer Layer

Page 47: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 48: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 49: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 50: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 51: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 52: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 53: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 54: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 55: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 56: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 57: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 58: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Page 59: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

PRESENTATION

DOMAIN

DATA

Page 60: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

PRESENTATION

DOMAIN

DATA REPOSITORY

Page 61: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

Page 62: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

interface Repository {

Observable query(query)

void remove(query)

void insert(item)

void update(item) }

Page 63: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

interface Repository {

Observable query(query) }

Page 64: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

interface Repository {

Observable query(query) }

CreateUserQuery

Page 65: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

interface Repository {

Observable query(query) }

CreateUserQuery

RemoveUserQuery

Page 66: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

interface Repository {

Observable query(query) }

CreateUserQuery

RemoveUserQuery

UpdateUserQuery

Page 67: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

interface Repository {

Observable query(query) }

CreateUserQuery

RemoveUserQuery

UpdateUserQuery

SelectUserQuery

Page 68: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

QUERY

Page 69: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

QUERYCreateUserQuery(id, name, gender)

Page 70: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

QUERY

interface Query {

boolean equals(other)

int hashCode() }

CreateUserQuery(id, name, gender)

Page 71: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

QUERY

interface Query {

boolean equals(other)

int hashCode() }

CreateUserQuery(id, name, gender)

Map<Query, Result>

Page 72: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

QUERY

interface Query {

boolean equals(other)

int hashCode() }

CreateUserQuery(id, name, gender)

Map<Query, Result>

Map<Query, Execution>

Page 73: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

Page 74: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

MEMORY DATA SOURCE

Page 75: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

MEMORY DATA SOURCE

FILE DATA SOURCE

Page 76: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

MEMORY DATA SOURCE

FILE DATA SOURCE

NETWORK DATA SOURCE

Page 77: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

REPOSITORY (DATA LAYER)

REPOSITORY

MEMORY DATA SOURCE

FILE DATA SOURCE

NETWORK DATA SOURCE

SINGLETON

Page 78: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

PRESENTATION

DOMAIN

DATA

Page 79: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

PRESENTATION

DOMAIN

DATA

USE CASE

Page 80: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

USE CASES (DOMAIN LAYER)

SESSION

Page 81: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

USE CASES (DOMAIN LAYER)

SESSIONSingle<Session> login(id, pass)

Completable logout()

Page 82: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

USE CASES (DOMAIN LAYER)

SESSIONSingle<Session> login(id, pass)

Completable logout()

REPOSITORY

Page 83: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

USE CASES (DOMAIN LAYER)

SESSION

REPOSITORY

logout()

Page 84: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

USE CASES (DOMAIN LAYER)

SESSION

REPOSITORY

logout()

delete

Page 85: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

USE CASES (DOMAIN LAYER)

SESSION

REPOSITORY

MESSAGES

logout()

delete

clear

Page 86: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

USE CASES (DOMAIN LAYER)

SESSION

REPOSITORY

MESSAGES

REPOSITORY

logout()

delete

clear

delete

Page 87: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

PRESENTATION

DOMAIN

DATA

Page 88: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

LAYERS

LAYER 1

LAYER 2

LAYER 3

PRESENTATION

DOMAIN

DATA

MVP

Page 89: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

MVP (PRESENTATION LAYER)

PRESENTER

VIEW

MODEL

Page 90: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

MVP (PRESENTATION LAYER)

PRESENTER

VIEW

MODELUSE CASE(S)

Page 91: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

MVP (PRESENTATION LAYER)

PRESENTER

VIEW

MODEL

interface LoginPresenter {

interface View { void showError(visible, code); void showProgress(visible); void showSuccess(); }

void onUserLogin(name, pass); void onUserAttemptedRetry(); }

USE CASE(S)

Page 92: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

VIEW

Page 93: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

VIEW

CLEAN PRESENTER

Page 94: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

VIEW

CLEAN PRESENTER LEGACY PRESENTER

Page 95: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

VIEW

CLEAN PRESENTER LEGACY PRESENTER

MOCK PRESENTER

Page 96: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

PRESENTER

Page 97: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

PRESENTER

DIALOG VIEW

Page 98: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

PRESENTER

DIALOG VIEW TOAST VIEW

Page 99: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

PRESENTER

DIALOG VIEW TOAST VIEW

SNACKBAR VIEW

Page 100: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

RISKS

Page 101: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

RISKS

• Might not work

Page 102: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

RISKS

• Might not work

• Overcomplicated

Page 103: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

RISKS

• Might not work

• Overcomplicated

• Too slow

Page 104: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

RISKS

• Might not work

• Overcomplicated

• Too slow

• Boring

Page 105: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

COST

Page 106: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

COST

• Learning curve

Page 107: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

COST

• Learning curve

• Refactoring cycles

Page 108: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

COST

• Learning curve

• Refactoring cycles

• Differences in ideas

Page 109: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

COST

• Learning curve

• Refactoring cycles

• Differences in ideas

• Have fun, never deliver :)

Page 110: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BENEFITS

Page 111: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BENEFITS

• Testability

Page 112: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BENEFITS

• Testability

• Standardisation

Page 113: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BENEFITS

• Testability

• Standardisation

• Code separation

Page 114: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

BENEFITS

• Testability

• Standardisation

• Code separation

• Maintainability

Page 115: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SAFELY

HOW WE MIGRATED

Page 116: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SAFELY

HOW WE MIGRATED

• Discuss

Page 117: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SAFELY

HOW WE MIGRATED

• Discuss• Assign 2 people

Page 118: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SAFELY

HOW WE MIGRATED

• Discuss• Assign 2 people• Never rewrite everything

Page 119: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SAFELY

HOW WE MIGRATED

• Discuss• Assign 2 people• Never rewrite everything• Keep old code to revert

Page 120: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SAFELY

HOW WE MIGRATED

• Discuss• Assign 2 people• Never rewrite everything• Keep old code to revert• Discuss

Page 121: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SPREAD THE KNOWLEDGE

CODE IS NOT ENOUGH

Page 122: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SPREAD THE KNOWLEDGE

CODE IS NOT ENOUGH

• Follow ups

Page 123: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SPREAD THE KNOWLEDGE

CODE IS NOT ENOUGH

• Follow ups• Code reviews

Page 124: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SPREAD THE KNOWLEDGE

CODE IS NOT ENOUGH

• Follow ups• Code reviews• Tutorials

Page 125: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SPREAD THE KNOWLEDGE

CODE IS NOT ENOUGH

• Follow ups• Code reviews• Tutorials• Samples

Page 126: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

SPREAD THE KNOWLEDGE

CODE IS NOT ENOUGH

• Follow ups• Code reviews• Tutorials• Samples• Tech talks

Page 127: Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin

@badootech

@openzloy

HTTPS://TECHBLOG.BADOO.COM

Danke!https://github.com/badoo/Chateau