SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Building robust apps:
Lessons from functional
programming and robotics
Props to this guy
Also this guy
YOU ARE DOING IT COMPLETELY WRONG
The Language of the System
on youtube
Match Android team
❏ Dheeraj Malik
❏ Aniruddh Bajirao
❏ Abhilash Reddy
❏ Aaron Dancygier
❏ David Brady
❏ Ramanand Reddi
❏ Martin Anderson
❏ Roshan Gupta
❏ Mohit Bhatt
❏ Wasim Ahmad
❏ Charles Neveu
Legacy app
● Originally written by contractors
● Grown by accretion
● Behavior becoming non-deterministic
● Adding new features becoming increasingly difficult
● Whack-a-mole debugging cycle
● Still crashing on users
Goals of the rewrite
● Eliminate crashes
● Easy to add/modify/AB test functionality
● Predictable behavior
Complications of
Android
Programming
Activity life-cycle
❏ Activities can be visible, partially visible, or invisible
❏ UI operations can only be done by an activity when it is visible
❏ Android apps are multi-threaded
❏ UI thread
❏ Needs to be responsive: Everything that can be done on a
background thread should be
❏ Background threads
❏ Place to do network routines, longish computations, etc.
❏ UI operations can only be done on the UI thread
❏ Network operations can never be done on UI thread
Crashing is not a good user experience
❏ Any of these can cause an app to crash
❏ UI operations can only be done by an activity when it is visible
❏ UI operations can only be done on the UI thread
❏ Network operations can never be done on UI thread
❏ So just make sure that stuff runs on the right thread…
❏ In general, no way to know what thread a piece of code will run on
❏ E.g. Activity class has runOnUIThread method but it takes a Runnable that can still call
anything
❏ … And no activity does UI operations unless it is visible.
❏ But visibility isn’t transactional.
It gets worse
● Activities can be destroyed (in the lifecycle
sense) while things still hold pointers to them
(in the GC sense)
● Plus all the usual multithreading issues
● Activity-centric programming makes it worse
Activity-centric
programming
● Is seeing the app as a set of Activities. In my experience, this is typically the
way product managers see them.
● But an activity is just a container for and gateway to UI elements
○ It’s how we gain access to textboxes, buttons, etc
○ It changes state based on user input.
But it can be so much more!
Activity as God Object
Everybody’s listener!
Everybody’s thread manager!
Everybody’s Controller!
All kinds of state variables!
ENGULFS Business logic!
Tightly coupled to everything!
AND ONLY ITKNOWS WHERE TO GO NEXT!
Activities are tightly coupled
class ActivityA extends Activity {
if (x) startActivity(ActivityB);
if (y) startActivity(ActivityC);
if (z) startActivity(ActivityD);
An app looks something like this
When is a data structure not a data structure?
When is a data structure not a data structure?
When it is implicit in the code!
❏ Can’t analyze it
❏ Can’t answer questions about it
❏ Tightly coupled, violates need to know
❏ Becomes nondeterministic
Sources of Complexity
❏ Complexity that comes with Android
❏ Concurrency
❏ Activity Lifecycle
❏ Problems we create for ourselves
❏ God objects
❏ Tight coupling
❏ Structure is implicit in the code
❏ No separate infrastructure
Out of the Tarpit*
One plausible solution (not necessarily the optimal solution, or only solution, but
steps in the right direction)
❏ Functional Dataflow architecture
❏ Publish/subscribe backbone (eventBus)
❏ Pass immutable data instead of objects or control
❏ Minimize internal state
❏ Controllers are independent of activity lifecycle, i.e. always on
❏ Transitions are handled by an explicit graph data structure
Out of the Tarpit, Ben Moseley and Peter Marks, Software Practice Advancement, 2006
http://shaffner.us/cs/papers/tarpit.pdf
Data processing structure
❏ Modules take inputs, produce outputs, with minimal
internal state
❏ Activities
❏ Take user inputs, publish data outputs
❏ Subscribe to data inputs, display output to user
❏ Controllers
❏ Subscribe to data, publish data
❏ Independent of activity lifecycle
Publish/subscribe backbone (eventBus)
❏ Pass immutable data
❏ Not objects, not control
❏ Awkward in Java
❏ Completely decouples producers and consumers
❏ Neither needs to know who (if anyone) is at the other end of the queue
❏ Avoids callback hell
❏ Match app has no explicit callbacks except those required by library apis e.g. retrofit
❏ Concurrency through onEvent<thread> handlers
❏ Match app has no AsyncTasks, no Runnables
❏ Activities only communicate over the bus
❏ Activities register in onResume, unregister in onPause
❏ Mockless testing
❏ Testing consists of sending and receiving messages
Reusable activities
❏ Activities are usually one-off
❏ Tightly coupled to subsequent activities
❏ Tightly coupled to backend calls
❏ Tightly coupled to business logic
❏ Reusable activities
❏ Communicate via event bus
❏ Translate user input into data
❏ post data to bus
❏ Subscribe to updates
❏ Decoupled from subsequent activities
❏ Flow information stored in separate graph data structure
❏ Decoupled from backend
❏ No explicit api calls
❏ No error handling
❏ Business logic resides in controller
Activity Flow Graph
❏ Graph data structure
❏ Nodes (vertices) are activities
❏ Links (edges) are directed transitions
❏ Based on finite state machine data structure by Van
Gurp et al.*
*On the Implementation of Finite State Machines, Jilles Van Gurp & Jan Bosch, 3rd Annual IASTED
International Conference Software Engineering and Applications October 6-8, 1999 - Scottsdale, Arizona,
USA
A typical activity (DailyMatches) from our old app
❏ Android lifecycle handlers
❏ Fragment navigation
❏ Intent handling/parsing/error-handling
❏ Show/hide progress bar
❏ Navigate to YoureInterested, TheyreInterested, MaybeInterested
❏ Get counts AsyncTask
DailyMatches refactored
❏ Android lifecycle handlers
❏ fragment navigation
❏ Intent handling/parsing/error-handling
❏ onEvent(DailyMatches);
❏ post(DailyMatchesRequest);
❏ Errors handled by separate common error manager
❏ show/hide progress bar
❏ Handled by whatever activity is on top
❏ navigate to YourInterested, TheyreInterested, MaybeInterested
❏ Explicit external graph
❏ get counts AsyncTask
❏ Handled by controller
Results
● Completed on schedule
● Number of crashes due to UI operations dropped to zero
● A/B test development speed greatly increased
● Improvement in all business metrics
Open issues
❏ Superclass/subclass interactions
❏ If a superclass defines an event handler, every registered instance of every subclass will
execute that handler (within the context of the instance’s state).
❏ Inline event handling vs. task handling.
❏ In EventBus, if a handler can execute on the same thread, it is executed in-line. If handler A
posts an event handled by handler B, handler B may run before A completes.
❏ Sticky messages, or not?
❏ Sticky messages stay on the bus until replaced, and objects that subscribe to them will receive
them when they register on the bus. UI objects typically register in onResume, so a fragment’s
event handler will be called every time it is resumes after dialog. Sticky messages can be
removed, introducing order dependence.
❏ Multiple busses
❏ We only used one bus. How does it affect development and maintenance to use multiple
busses?

Weitere ähnliche Inhalte

Andere mochten auch

Copia De Laboratorio De Quimica El Proyecto
Copia De Laboratorio De Quimica El ProyectoCopia De Laboratorio De Quimica El Proyecto
Copia De Laboratorio De Quimica El Proyectomajo192890
 
Muligheder for fremtidens huse
Muligheder for fremtidens huseMuligheder for fremtidens huse
Muligheder for fremtidens husefremtidensomfag
 
miguel orosco face book
miguel orosco face bookmiguel orosco face book
miguel orosco face bookmigu6666
 
Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo
Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo
Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo JoseLuis900
 
Feliz cumplenos
Feliz cumplenosFeliz cumplenos
Feliz cumplenosvictor
 
Encunetro 3 la enseñanza de la historia en la
Encunetro 3 la enseñanza de la historia en laEncunetro 3 la enseñanza de la historia en la
Encunetro 3 la enseñanza de la historia en laFulvia Condori
 
Redes sociales evolucion al infinito
Redes sociales evolucion al infinitoRedes sociales evolucion al infinito
Redes sociales evolucion al infinitoCarlos Vargas H.
 
Populære kæledyr i 2025
Populære kæledyr i 2025Populære kæledyr i 2025
Populære kæledyr i 2025fremtidensomfag
 
Tüneller için modüler konumlandırma ve İrtibat sistemi
Tüneller için modüler konumlandırma ve İrtibat sistemiTüneller için modüler konumlandırma ve İrtibat sistemi
Tüneller için modüler konumlandırma ve İrtibat sistemiRealTrac International
 
El sistema de posicionamiento local y comunicación para logística
El sistema de posicionamiento local y comunicación para logísticaEl sistema de posicionamiento local y comunicación para logística
El sistema de posicionamiento local y comunicación para logísticaRealTrac International
 
Extensión del mundo biblico
Extensión del mundo biblicoExtensión del mundo biblico
Extensión del mundo biblicodietkliewer
 
Rafael Uribe Uribe
Rafael Uribe UribeRafael Uribe Uribe
Rafael Uribe UribeSomos Más
 
Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...
Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...
Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...M. HECHAM EL KHARRAZ
 

Andere mochten auch (20)

Copia De Laboratorio De Quimica El Proyecto
Copia De Laboratorio De Quimica El ProyectoCopia De Laboratorio De Quimica El Proyecto
Copia De Laboratorio De Quimica El Proyecto
 
Muligheder for fremtidens huse
Muligheder for fremtidens huseMuligheder for fremtidens huse
Muligheder for fremtidens huse
 
miguel orosco face book
miguel orosco face bookmiguel orosco face book
miguel orosco face book
 
Fremtidens huse
Fremtidens huseFremtidens huse
Fremtidens huse
 
Actividad Yo, Región y Cultura
Actividad Yo, Región y CulturaActividad Yo, Región y Cultura
Actividad Yo, Región y Cultura
 
Escuela Nº 354
Escuela Nº 354Escuela Nº 354
Escuela Nº 354
 
Final monografia weir v2
Final monografia weir v2Final monografia weir v2
Final monografia weir v2
 
Por nuestros muertos
Por nuestros muertosPor nuestros muertos
Por nuestros muertos
 
Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo
Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo
Aplicar las Herramientas del Sistema para la Preservación del Equipo de Computo
 
Feliz cumplenos
Feliz cumplenosFeliz cumplenos
Feliz cumplenos
 
Encunetro 3 la enseñanza de la historia en la
Encunetro 3 la enseñanza de la historia en laEncunetro 3 la enseñanza de la historia en la
Encunetro 3 la enseñanza de la historia en la
 
Redes sociales evolucion al infinito
Redes sociales evolucion al infinitoRedes sociales evolucion al infinito
Redes sociales evolucion al infinito
 
C:\Documents And Settings\Lsoto\Mis Documentos\Freddy Murphy\Freddy Murphy
C:\Documents And Settings\Lsoto\Mis Documentos\Freddy Murphy\Freddy MurphyC:\Documents And Settings\Lsoto\Mis Documentos\Freddy Murphy\Freddy Murphy
C:\Documents And Settings\Lsoto\Mis Documentos\Freddy Murphy\Freddy Murphy
 
Populære kæledyr i 2025
Populære kæledyr i 2025Populære kæledyr i 2025
Populære kæledyr i 2025
 
Tüneller için modüler konumlandırma ve İrtibat sistemi
Tüneller için modüler konumlandırma ve İrtibat sistemiTüneller için modüler konumlandırma ve İrtibat sistemi
Tüneller için modüler konumlandırma ve İrtibat sistemi
 
El sistema de posicionamiento local y comunicación para logística
El sistema de posicionamiento local y comunicación para logísticaEl sistema de posicionamiento local y comunicación para logística
El sistema de posicionamiento local y comunicación para logística
 
Informe oea drogas
Informe oea drogasInforme oea drogas
Informe oea drogas
 
Extensión del mundo biblico
Extensión del mundo biblicoExtensión del mundo biblico
Extensión del mundo biblico
 
Rafael Uribe Uribe
Rafael Uribe UribeRafael Uribe Uribe
Rafael Uribe Uribe
 
Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...
Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...
Desarrollo de una metodologia para la obtencion de imagenes de inercia termic...
 

Ähnlich wie Building robust apps

Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUGslandelle
 
Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Demi Ben-Ari
 
Thinking DevOps in the era of the Cloud - Demi Ben-Ari
Thinking DevOps in the era of the Cloud - Demi Ben-AriThinking DevOps in the era of the Cloud - Demi Ben-Ari
Thinking DevOps in the era of the Cloud - Demi Ben-AriDemi Ben-Ari
 
How to Manage the Risk of your Polyglot Environments
How to Manage the Risk of your Polyglot EnvironmentsHow to Manage the Risk of your Polyglot Environments
How to Manage the Risk of your Polyglot EnvironmentsDevOps.com
 
Monitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafaMonitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafaLama K Banna
 
Aws uk ug #8 not everything that happens in vegas stay in vegas
Aws uk ug #8   not everything that happens in vegas stay in vegasAws uk ug #8   not everything that happens in vegas stay in vegas
Aws uk ug #8 not everything that happens in vegas stay in vegasPeter Mounce
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
 
Five android architecture
Five android architectureFive android architecture
Five android architectureTomislav Homan
 
Eric Proegler Early Performance Testing from CAST2014
Eric Proegler Early Performance Testing from CAST2014Eric Proegler Early Performance Testing from CAST2014
Eric Proegler Early Performance Testing from CAST2014Eric Proegler
 
Design | expose ap is with cqr
Design | expose ap is with cqrDesign | expose ap is with cqr
Design | expose ap is with cqrJabar Asadi
 
Break Up the Monolith- Testing Microservices by Marcus Merrell
Break Up the Monolith- Testing Microservices by Marcus MerrellBreak Up the Monolith- Testing Microservices by Marcus Merrell
Break Up the Monolith- Testing Microservices by Marcus MerrellSauce Labs
 
Design | expose ap is with cqrs
Design | expose ap is with cqrsDesign | expose ap is with cqrs
Design | expose ap is with cqrselazhiA
 
Lambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big dataLambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big dataTrieu Nguyen
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragmentsVitali Pekelis
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOJosh Cypher
 
The Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security TestingThe Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security TestingMatt Tesauro
 
Justin Ison
Justin IsonJustin Ison
Justin IsonCodeFest
 

Ähnlich wie Building robust apps (20)

Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUG
 
Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"
 
Thinking DevOps in the era of the Cloud - Demi Ben-Ari
Thinking DevOps in the era of the Cloud - Demi Ben-AriThinking DevOps in the era of the Cloud - Demi Ben-Ari
Thinking DevOps in the era of the Cloud - Demi Ben-Ari
 
How to Manage the Risk of your Polyglot Environments
How to Manage the Risk of your Polyglot EnvironmentsHow to Manage the Risk of your Polyglot Environments
How to Manage the Risk of your Polyglot Environments
 
Monitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafaMonitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafa
 
Aws uk ug #8 not everything that happens in vegas stay in vegas
Aws uk ug #8   not everything that happens in vegas stay in vegasAws uk ug #8   not everything that happens in vegas stay in vegas
Aws uk ug #8 not everything that happens in vegas stay in vegas
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
 
Five android architecture
Five android architectureFive android architecture
Five android architecture
 
Eric Proegler Early Performance Testing from CAST2014
Eric Proegler Early Performance Testing from CAST2014Eric Proegler Early Performance Testing from CAST2014
Eric Proegler Early Performance Testing from CAST2014
 
Design | expose ap is with cqr
Design | expose ap is with cqrDesign | expose ap is with cqr
Design | expose ap is with cqr
 
Break Up the Monolith- Testing Microservices by Marcus Merrell
Break Up the Monolith- Testing Microservices by Marcus MerrellBreak Up the Monolith- Testing Microservices by Marcus Merrell
Break Up the Monolith- Testing Microservices by Marcus Merrell
 
Design | expose ap is with cqrs
Design | expose ap is with cqrsDesign | expose ap is with cqrs
Design | expose ap is with cqrs
 
Lambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big dataLambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big data
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragments
 
Sea of Data
Sea of DataSea of Data
Sea of Data
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIO
 
Fuzzing - Part 2
Fuzzing - Part 2Fuzzing - Part 2
Fuzzing - Part 2
 
The Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security TestingThe Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security Testing
 
Android by Swecha
Android by SwechaAndroid by Swecha
Android by Swecha
 
Justin Ison
Justin IsonJustin Ison
Justin Ison
 

Building robust apps

  • 1. Building robust apps: Lessons from functional programming and robotics
  • 3. Also this guy YOU ARE DOING IT COMPLETELY WRONG The Language of the System on youtube
  • 4. Match Android team ❏ Dheeraj Malik ❏ Aniruddh Bajirao ❏ Abhilash Reddy ❏ Aaron Dancygier ❏ David Brady ❏ Ramanand Reddi ❏ Martin Anderson ❏ Roshan Gupta ❏ Mohit Bhatt ❏ Wasim Ahmad ❏ Charles Neveu
  • 5. Legacy app ● Originally written by contractors ● Grown by accretion ● Behavior becoming non-deterministic ● Adding new features becoming increasingly difficult ● Whack-a-mole debugging cycle ● Still crashing on users
  • 6. Goals of the rewrite ● Eliminate crashes ● Easy to add/modify/AB test functionality ● Predictable behavior
  • 8. Activity life-cycle ❏ Activities can be visible, partially visible, or invisible ❏ UI operations can only be done by an activity when it is visible ❏ Android apps are multi-threaded ❏ UI thread ❏ Needs to be responsive: Everything that can be done on a background thread should be ❏ Background threads ❏ Place to do network routines, longish computations, etc. ❏ UI operations can only be done on the UI thread ❏ Network operations can never be done on UI thread
  • 9. Crashing is not a good user experience ❏ Any of these can cause an app to crash ❏ UI operations can only be done by an activity when it is visible ❏ UI operations can only be done on the UI thread ❏ Network operations can never be done on UI thread ❏ So just make sure that stuff runs on the right thread… ❏ In general, no way to know what thread a piece of code will run on ❏ E.g. Activity class has runOnUIThread method but it takes a Runnable that can still call anything ❏ … And no activity does UI operations unless it is visible. ❏ But visibility isn’t transactional.
  • 10. It gets worse ● Activities can be destroyed (in the lifecycle sense) while things still hold pointers to them (in the GC sense) ● Plus all the usual multithreading issues ● Activity-centric programming makes it worse
  • 11. Activity-centric programming ● Is seeing the app as a set of Activities. In my experience, this is typically the way product managers see them. ● But an activity is just a container for and gateway to UI elements ○ It’s how we gain access to textboxes, buttons, etc ○ It changes state based on user input. But it can be so much more!
  • 12. Activity as God Object Everybody’s listener! Everybody’s thread manager! Everybody’s Controller! All kinds of state variables! ENGULFS Business logic! Tightly coupled to everything! AND ONLY ITKNOWS WHERE TO GO NEXT!
  • 13. Activities are tightly coupled class ActivityA extends Activity { if (x) startActivity(ActivityB); if (y) startActivity(ActivityC); if (z) startActivity(ActivityD);
  • 14. An app looks something like this
  • 15. When is a data structure not a data structure?
  • 16. When is a data structure not a data structure? When it is implicit in the code! ❏ Can’t analyze it ❏ Can’t answer questions about it ❏ Tightly coupled, violates need to know ❏ Becomes nondeterministic
  • 17. Sources of Complexity ❏ Complexity that comes with Android ❏ Concurrency ❏ Activity Lifecycle ❏ Problems we create for ourselves ❏ God objects ❏ Tight coupling ❏ Structure is implicit in the code ❏ No separate infrastructure
  • 18. Out of the Tarpit* One plausible solution (not necessarily the optimal solution, or only solution, but steps in the right direction) ❏ Functional Dataflow architecture ❏ Publish/subscribe backbone (eventBus) ❏ Pass immutable data instead of objects or control ❏ Minimize internal state ❏ Controllers are independent of activity lifecycle, i.e. always on ❏ Transitions are handled by an explicit graph data structure Out of the Tarpit, Ben Moseley and Peter Marks, Software Practice Advancement, 2006 http://shaffner.us/cs/papers/tarpit.pdf
  • 19. Data processing structure ❏ Modules take inputs, produce outputs, with minimal internal state ❏ Activities ❏ Take user inputs, publish data outputs ❏ Subscribe to data inputs, display output to user ❏ Controllers ❏ Subscribe to data, publish data ❏ Independent of activity lifecycle
  • 20. Publish/subscribe backbone (eventBus) ❏ Pass immutable data ❏ Not objects, not control ❏ Awkward in Java ❏ Completely decouples producers and consumers ❏ Neither needs to know who (if anyone) is at the other end of the queue ❏ Avoids callback hell ❏ Match app has no explicit callbacks except those required by library apis e.g. retrofit ❏ Concurrency through onEvent<thread> handlers ❏ Match app has no AsyncTasks, no Runnables ❏ Activities only communicate over the bus ❏ Activities register in onResume, unregister in onPause ❏ Mockless testing ❏ Testing consists of sending and receiving messages
  • 21. Reusable activities ❏ Activities are usually one-off ❏ Tightly coupled to subsequent activities ❏ Tightly coupled to backend calls ❏ Tightly coupled to business logic ❏ Reusable activities ❏ Communicate via event bus ❏ Translate user input into data ❏ post data to bus ❏ Subscribe to updates ❏ Decoupled from subsequent activities ❏ Flow information stored in separate graph data structure ❏ Decoupled from backend ❏ No explicit api calls ❏ No error handling ❏ Business logic resides in controller
  • 22. Activity Flow Graph ❏ Graph data structure ❏ Nodes (vertices) are activities ❏ Links (edges) are directed transitions ❏ Based on finite state machine data structure by Van Gurp et al.* *On the Implementation of Finite State Machines, Jilles Van Gurp & Jan Bosch, 3rd Annual IASTED International Conference Software Engineering and Applications October 6-8, 1999 - Scottsdale, Arizona, USA
  • 23. A typical activity (DailyMatches) from our old app ❏ Android lifecycle handlers ❏ Fragment navigation ❏ Intent handling/parsing/error-handling ❏ Show/hide progress bar ❏ Navigate to YoureInterested, TheyreInterested, MaybeInterested ❏ Get counts AsyncTask
  • 24. DailyMatches refactored ❏ Android lifecycle handlers ❏ fragment navigation ❏ Intent handling/parsing/error-handling ❏ onEvent(DailyMatches); ❏ post(DailyMatchesRequest); ❏ Errors handled by separate common error manager ❏ show/hide progress bar ❏ Handled by whatever activity is on top ❏ navigate to YourInterested, TheyreInterested, MaybeInterested ❏ Explicit external graph ❏ get counts AsyncTask ❏ Handled by controller
  • 25. Results ● Completed on schedule ● Number of crashes due to UI operations dropped to zero ● A/B test development speed greatly increased ● Improvement in all business metrics
  • 26. Open issues ❏ Superclass/subclass interactions ❏ If a superclass defines an event handler, every registered instance of every subclass will execute that handler (within the context of the instance’s state). ❏ Inline event handling vs. task handling. ❏ In EventBus, if a handler can execute on the same thread, it is executed in-line. If handler A posts an event handled by handler B, handler B may run before A completes. ❏ Sticky messages, or not? ❏ Sticky messages stay on the bus until replaced, and objects that subscribe to them will receive them when they register on the bus. UI objects typically register in onResume, so a fragment’s event handler will be called every time it is resumes after dialog. Sticky messages can be removed, introducing order dependence. ❏ Multiple busses ❏ We only used one bus. How does it affect development and maintenance to use multiple busses?