RxJava’s Characteristics

RxJava’s Characteristics

RxJava has below functional patterns

Observer Pattern

RxJava is a classic example of the Observer Pattern. We start with the Observable, which is the source of our data. Then we have one or more Observers, which subscribe to the Observable and get notified when there is a new event. This allows for a push-based mechanism, which is usually far more ideal than continually polling for new events. RxJava adds to the traditional Observer Pattern, however, by also having the Observable signal completion and errors along with regular events

Iterator Pattern

With a traditional Iterator Pattern, the iterator pulls data from the underlying collection, which would implement some sort of Iterable interface

The Observable was designed to be the dual of the Iterable. Instead of pulling data out of an Iterable with .next(), the Observable pushes data to an Observer using .onNext(). So, where the Iterator Pattern uses synchronous pulling of data, RxJava allows for asynchronous pushing of data, allowing code to be truly reactive

Functional Programming

One of the most important aspects of RxJava is that it uses functional programming, in particular, with its Operators. Functional programming is programming with pure functions. A pure function is one that satisfies the following two conditions:

  • The function always returns the same value given the same input (i.e. it’s deterministic). This implies that the function cannot depend on any global state (e.g. a Java class’s member variable) nor any external resource (e.g. a web service).
  • The function does not cause any side effects. This means that the function cannot mutate any input parameter, update any global state, or interact with any external resource