Download presentation
Presentation is loading. Please wait.
1
Reactive Android Development
CS T & CS T Summer 2016 RxAndroid Continued
2
Invariants Reactive programming should be thought of in terms of invariants This is particularly true for Sodium But also applies to the Reactive Extensions The simplest example is 'map' sum = list.map(l -> add_up_the_elements(l)) Once this is established, no matter what happens to the size or content of list, sum will always be equal to the sum of its elements.
3
Invariants Aid Correctness
This isn't anything new Remember the inductive proof for insertion sort List A = <random list of elements>; List Sorted = <empty list>; for(element a : A) { Sorted = insert_element(a,Sorted); }
4
DRY (Don't Repeat Yourself)
This is a standard software engineering principle Enforcing the same invariant in multiple places leads to brittle code If the invariant changes, you will have to hunt for all of the places that might be impacted by the change.
5
The Challenge Find a way to state your requirements in terms of invariants that can be enforced in only one statement.
6
"Beware the man with one gun"
7
Beware the man with one gun
Or, if you prefer "No man can serve two masters"
8
Beware the man with one gun
Or, if you prefer "No man can serve two masters" Each of your stages should enforce only one invariant
9
Observables The basic element of Rx Observable Hot Cold
10
Observers OnNext OnCompleted OnError
11
observeOn & subscribeOn
12
Cleaning Up References
If your activity subscribes to an observable, then the observable maintains a reference to your activity Even if the Android OS tries to delete your activity, it won't be garbage-collected.
13
Cleaning Up References
The subscribe method returns an Rx.Subscription object that can be used to unsubscribe In the OnDestroy method, for example.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.