We are beginning to notice that the current financial stock retrieval flow is getting quite big and unwieldy. The current Observable creation code takes more than 50 lines, and it will soon be hard to understand what is going on at all.
Obviously, in cases like these, we need to refactor code to make it simpler so that it becomes easier to understand and work with.
This chapter will explore just that. We will learn how to extract methods to make code simpler. Method extraction will be used to simplify and properly name consumers or the code that creates Observables.
Next, we will cover Observable Transformations that allow creating code that can modify an Observable in multiple ways as part of a flow. These techniques can be used to create simple custom caching or persistence mechanisms for the reactive streams.
We will see how we can use Observable Transformations to persist results into a file-based cache or track execution time.
Finally, the topics discussed in this chapter are these:
- How to extract code into more maintainable methods
- How can IDE be used to help with the refactoring
- How to extract complex Observable steps into a Transformer interface
- How to use Transformer interface to create for caching and debugging