Paso a paso explico como estructurar nuestros proyectos para ir solucionando y separando problemas para ver finalmente como la foto general de lo que hemos montado coincide con los principios de Clean Architecture y como esto nos ayuda a construir un software más solido, extensible y refactorizable.
10. The best approach when you apply “Clean
Architecture” is to use common sense
by Rafael Aguilar (@Rais38)
11. The best approach when you apply “Clean
Architecture” is to use common sense
by Rafael Aguilar (@Rais38)
Todas las arquitecturas caducan
Martin Fowler - SacrificialArchitecture
http://martinfowler.com/bliki/SacrificialArchitecture.html
14. Matando la God Activity
VIEW
Activity
Fragment
Widget
...
View
Interface
Todo lo
demás
15. Matando la God Activity
Render Methods,
View Lifecycle and
View Configuration
Todo lo
demás
View
Interface
16. Lógica de vista y Navegación
VIEW
PRESENTER
View Logic
Navigation
ROUTER
View
Interface
Navigation LAUNCHER
Implementation
Navigation
Launcher
Interface
Interface
Todo lo
demás
Opcional
17. Lógica de vista y Navegación
VIEW
PRESENTER
View Logic
Navigation
ROUTER
View
Interface
Navigation LAUNCHER
Implementation
Navigation
Launcher
Interface
Interface
Todo lo
demás
Opcional
18. Lógica de vista y Navegación
VIEW
Procesar eventos de vista
Solicitar datos
Controlar la vista
Guardar estado de la vista
goTo
goToNext
back
View
Interface
startActivity
fragment transactions
Interface
Todo lo
demás
Opcional
PAGE
19. 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
20. Para solucionar el problema de los giros de pantalla
mantener en la vista la referencia al Presenter
entre cambios de configuración gracias a:
onRetainCustomNonConfigurationInstance
getLastCustomNonConfigurationInstance
Sólo
en
la
Activity
21. Para solucionar el problema de los giros de pantalla
mantener en la vista la referencia al Presenter
entre cambios de configuración gracias a:
onRetainCustomNonConfigurationInstance
getLastCustomNonConfigurationInstance
Sólo
en
la
Activity
22. abstract public class PresenterFragment<K extends PresenterFragment, T>
extends Fragment implements Presenter<T> {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
abstract public void init(K presenter);
}
private void initializePresenter() {
FragmentManager fm = getFragmentManager();
MyPresenter retainedMyPresenter =
(MyPresenter) fm.findFragmentByTag(MyPresenter.class.getName());
if (retainedMyPresenter == null) {
fm.beginTransaction().add(
mMyPresenter, MyPresenter.class.getName()).commit();
} else {
retainedMyPresenter.init(mMyPresenter);
mMyPresenter = retainedMyPresenter;
}
}
26. Lógica y proveedores de datos
Repository
Interface
REPOSITORY
INTERACTOR
INTERACTOR
INTERACTOR
DataSource
Interface
DataSource
Interface
API
DataSource
CACHE
DataSource
27. Lógica y proveedores de datos
Políticas de cacheo
Lógica de origen de datos
INTERACTOR
INTERACTOR
INTERACTOR
DataSource
Interface
DataSource
Interface
Integración con los
proveedores de
datos
Integración con los
proveedores de
datos
Repository
Interface
36. ¿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.
37. EN RESUMEN
Aplica el sentido común
No dejes de ser autocrítico y crítico
Divide y vencerás
38. Show me the code!
https://github.com/android10/Android-CleanArchitecture
https://github.com/PaNaVTEC/Clean-Contacts
39. Gente con aura de tochez
que sabe de arquitectura
@pedro_g_s @PaNaVTEC@sefford
@Akelael @fernando_cejas @flipper83
Saúl Díaz
Android Engineer en Chicisimo
Pedro Gómez
Android Expert en Karumi
Christian Panadero
Android Developer en IG
Rubén Serrano
Lead Android Developer en Redbooth
Fernando Cejas
Android Developer en SoundCloud
Jorge Barroso
Cofounder y Android Expert en Karumi
Pablo Guardiola
Software Engineer en Telefonica I+D
@Guardiola31337
40. Referencias
Fernando 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=ROdIvrLL1ao
Pedro Gómez - Software Design Patterns
https://www.youtube.com/watch?v=tt3zI9cKiWU
Pedro Gómez - Effective Android UI
https://www.youtube.com/watch?v=N6yqe88ysNw
Rubén Serrano y José Manuel Pereira - Arquitectura Hexagonal en Android
https://www.youtube.com/watch?v=C3e3AwOTohg
Christian Panadero - My way to Clean Architecture
https://www.youtube.com/watch?v=lOEOK3UvmJM
Pablo Guardiola - What is all this Clean Architecture jibber-jabber about?
http://pguardiola.com/blog/clean-architecture-part-1/
Uncle Bob- The Clean Architecture
http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
41. Preguntas
José Manuel Pereira García
(JMPergar)
ANDROID TECH LEAD
www.jmpergar.com
@JMPergar
jm.pereira.g@gmail.com
+JoseMPereira