limpiando espero la arquitectura que yo quiero

Post on 26-Jul-2015

979 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Limpiando esperola arquitectura que yo quiero

José Manuel Pereira GarcíaANDROID TEAM LEAD

Clean Architecture for Android

José Manuel Pereira GarcíaANDROID TEAM LEAD

www.jmpergar.com@JMPergar

jm.pereira.g@gmail.com+JoseMPereira

We are hiringwearehiring@jobandtalent.com

Objetivos y premisas

Evitar el efecto L’Oréal(No elegir una arquitectura “porque yo lo valgo”)

Mantenible

MantenibleExtensible

MantenibleExtensible

Testable

MantenibleExtensible

Testable

Refactorizable

The best approach when you apply “Clean Architecture” is to use common sense

by Rafael Aguilar (@Rais38)

Todas las arquitecturas caducanMartin Fowler - SacrificialArchitecture

http://martinfowler.com/bliki/SacrificialArchitecture.html

Separandoproblemas

single responsibility principleAll you need is SRP

Matando la God Activity

VIEWActivity

FragmentWidget

...

View

In

terfa

ce Todo lodemás

Matando la God Activity

Render Methods, View Lifecycle and View Configuration

Todo lodemásVi

ewIn

terfa

ce

Lógica de vista y Navegación

VIEW PRESENTERView Logic

NavigationROUTER

View

In

terfa

ceNavigation LAUNCHER

Implementation

Navig

atio

n La

unch

er

Inte

rface

Inte

rface Todo lo

demás

Opcional

Lógica de vista y Navegación

VIEWProcesar eventos de vista

Solicitar datosControlar la vista

Guardar estado de la vista

goTogoToNext

back

View

In

terfa

cestartActivity

fragment transactions

Navig

atio

n La

unch

er

Inte

rface

Inte

rface Todo lo

demás

Opcional

Flujo

View Presenter Domain

Flujo de llamadas

Click : Refresh Button

Active Loading Request Data

Response Error

Render Empty State Error

Click : Retry

Active Empty State Loading Request Data

Response DataDisable Loading

Disable Loading

Render Data

Para solucionar el problema de los giros de pantallamantener en la vista la referencia al Presenter

entre cambios de configuración gracias a:onRetainCustomNonConfigurationInstancegetLastCustomNonConfigurationInstance

Sólo en la

Activity

Lógica de negocio

PRESENTER

ROUTER

View

In

terfa

ceNa

vigat

ion

Laun

cher

In

terfa

ce

Use

Case

s In

terfa

ce INTERACTOR

INTERACTOR

INTERACTOR

Inte

rface Todo lo

demás

Lógica de negocio

PRESENTER

ROUTER

View

In

terfa

ceNa

vigat

ion

Laun

cher

In

terfa

ce

Validación de datos

Obtención de datos

Procesamiento de datos

Inte

rface Todo lo

demás

Use

Case

s In

terfa

ce

Lógica de negocio

View

In

terfa

ceNa

vigat

ion

Laun

cher

In

terfa

ce

Inte

rface Todo lo

demás

background tasks

Interactor >> RunnableThreadExecutor >> ThreadPoolExecutorPostExecutionThread >> MainThread Handler

Use

Case

s In

terfa

ce INTERACTOR

INTERACTOR

INTERACTOR

PRESENTER

ROUTER

Lógica y proveedores de datos

ActivityFragment

Widget...

View Logic(Presenter)

NavigationRouter

View

In

terfa

ce

Navigation Launcher Implementation

Navig

atio

n La

unch

er

Inte

rface

Use

Case

s

Repo

sito

ry

Inte

rface

REPOSITORY

INTERACTOR

INTERACTOR

INTERACTOR

Data

Sour

ce

Inte

rface

Data

Sour

ce

Inte

rface

APIDataSource

CACHEDataSource

Lógica y proveedores de datos

ActivityFragment

Widget...

View Logic(Presenter)

NavigationRouter

View

In

terfa

ce

Navigation Launcher Implementation

Navig

atio

n La

unch

er

Inte

rface

Use

Case

s Políticas de cacheoLógica de origen de datos

INTERACTOR

INTERACTOR

INTERACTOR

Data

Sour

ce

Inte

rface

Data

Sour

ce

Inte

rface

Integración con los proveedores de

datos

Integración con los proveedores de

datos

Repo

sito

ry

Inte

rface

CleanArchitecture

ActivityFragment

Widget...

View Logic(Presenter)

NavigationRouter

View

Inte

rface

Navigation Launcher Implementation

Navig

atio

n La

unch

er

Inte

rface

Use

Case

s

Repo

sito

ry

Inte

rface

INTERACTOR

INTERACTOR

INTERACTOR

Data

Sour

ce

Inte

rface

Data

Sour

ce

Inte

rface

APIDataSource

CACHEDataSource

REPOSITORY

ENTIDADESUI

PRES

ENTE

RS

INTERACTORS

REPOSITORIES

DATA SOURCES

ENTIDADESUI

PRES

ENTE

RS

INTERACTORS

REPOSITORIES

DATA SOURCES

AbstraccionesConcreciones Concreciones

ENTIDADESUI

PRES

ENTE

RS

INTERACTORS

REPOSITORIES

DATA SOURCES

AbstraccionesConcreciones Concreciones

JAVAANDROID ANDROID

ENTIDADESUI

PRES

ENTE

RS

INTERACTORS

REPOSITORIES

DATA SOURCES

AbstraccionesConcreciones Concreciones

JAVAANDROID ANDROID

Regla de la dependenciaRegla de la dependencia

¿Que hemos conseguido?

● Arquitectura independiente del framework, UI y proveedores de datos.

● Una arquitectura modular horizontal y verticalmente.● Separar problemas y mejorar la legibilidad del código.● Solucionar el problema de los cambios de configuración.● Simplificar el problema de ejecución en segundo plano.● Declarar el objetivo de tu software gracias a los interactors.

Show me the code!

Gente a la que debo una cerveza

@pedro_g_s @PaNaVTEC@sefford

@Akelael @fernando_cejas @flipper83

Saúl DíazAndroid Engineer en ChicisimoPedro GómezAndroid Expert en KarumiChristian PanaderoAndroid Developer en MoniRubén SerranoLead Android Developer en RedboothFernando CejasAndroid Developer en SoundCloudJorge BarrosoCofounder y Android Expert en Karumi

ReferenciasFernando Cejas - Architecting Android…The clean way?

http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/Jorge Barroso - Forgetting Android

https://www.youtube.com/watch?v=ROdIvrLL1aoPedro Gómez - Software Design Patterns

https://www.youtube.com/watch?v=tt3zI9cKiWUPedro Gómez - Effective Android UI

https://www.youtube.com/watch?v=N6yqe88ysNwRubén Serrano y José Manuel Pereira - Arquitectura Hexagonal en Android

https://www.youtube.com/watch?v=C3e3AwOTohgChristian Panadero - My way to Clean Architecture

https://www.youtube.com/watch?v=lOEOK3UvmJMUncle Bob- The Clean Architecture

http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html

Preguntas

José Manuel Pereira GarcíaANDROID TEAM LEAD

www.jmpergar.com

@JMPergar

jm.pereira.g@gmail.com

+JoseMPereira

GRACIAS

top related