Mixing object-oriented and reactive programming
As you start applying your RxJava knowledge to real-world problems, something that may not immediately be clear is how to mix it with object-oriented programming. Leveraging multiple paradigms such as object-oriented and functional programming is becoming increasingly common. Reactive programming and object-oriented programming, especially in a Java environment, can definitely work together for the greater good.
Obviously, you can emit any type T
from an Observable
or any of the other reactive types. Emitting objects built off your own classes is one way object-oriented and reactive programming work together. We have seen a number of examples in this book. For instance, Java 8's LocalDate
is a complex object-oriented type, but you can push it through an Observable<LocalDate>
, as shown in the following code:
import io.reactivex.Observable; import java.time.LocalDate; public class Launcher { public static void main(String[] args) {...