A Great Way to do Android Presenters
Article Summary
Cash App's Android team chose presenters over ViewModels and MVVM. Here's why their "boring" code wins.
Benoît Quenaudon from Cash App shares their presenter pattern that uses RxJava to create a uniform, testable architecture. Every presenter follows the same contract: view events in, view models out.
Key Takeaways
- Single API: all presenters extend ObservableTransformer with one input and output stream
- Strict top-down data flow prevents the nightmare of reasoning about upward streams
- Navigation handled as side effects through Launcher interface, not view model emissions
- Testing simplified with fake implementations and RxJava's test observers
A consistent presenter pattern with unidirectional data flow creates code that's easy to write, review, and test across the entire team.
About This Article
Cash App's Android team needed a presenter pattern that enforces unidirectional data flow. Data had to move strictly downward from view events to view models, avoiding the complexity that comes when data flows back up through asynchronous streams.
Benoit Quenaudon's team built presenters that extended ObservableTransformer with a waterfall visualization approach. Database queries and asynchronous sources only execute when the stream gets subscribed to, not when the presenter is created. They used RxJava's merge and publish operators to make this work.
The presenter contract delegated side effects to a Launcher interface, which made testing straightforward. The team could verify behavior like URL launches using PublishSubject and TestObserver without needing complex mocking frameworks.