Until now, we have used method extraction technique to simplify Consumers (actions), .flatMap(), and other similar calls. However, there is a slight difference when we are creating a method to create something that can be used completely independently in multiple places, as opposed to a method that was just used to extract a tightly-coupled piece of code.
Such an approach is called a Factory Method pattern--it is basically a method that hides the complexity of object creation.
In our code, we have a few candidates for that and all of them create complex Observables that produce StockUpdate objects:
- Financial stock quote retrieval from the Yahoo API
- Tweet monitoring
- Backup flow that reads items from local database
All these Observables have relatively complex creation code and they can definitely be reused in other places independently (for example, if we decide that we want to see just the tweets).