Why are Flowables not Observables; Observable interface is pretty much a subset of Flowable, their implementations are pretty much the same.
Why don't they implement a common interface so we can directly cast Flowable as Observable?
Why are Flowables not Observables
Conceptional separation. I would have gone with Flowable
only because that can do all the other types. The community, however, were strongly into reflecting the major behavioral property in separate types: Single
, Maybe
, Completable
...
Observable interface is pretty much a subset of Flowable
This is a common viewpoint from people who likely don't program on a daily basis. Unfortunately for them, the type system and language (Java) doesn't let such high-level abstractions get specialized easily or at all.
Plus, implementing backpressure requires specific algorithms and building blocks and can get quite complicated. I encourage you to check out the difference between one of the more difficult operators: Flowable.flatMapIterable vs Observable.flatMapIterable.
Why don't they implement a common interface so we can directly cast Flowable as Observable
Flowable
implements the Reactive-Streams interfaces and thus we can't just declare Subscriber extends Observer
and Subscription extends Disposable
.
Furthermore, at one time in early v2, Observable
implemented Publisher
and caused massive amounts of ambiguity and manual casting would have been a major pain point for library users.
A small regret about introducing backpressure in RxJava 0.x is that instead of having a separate base reactive class, the Observable itself was retrofitted. The main issue with backpressure is that many hot sources, such as UI events, can't be reasonably backpressured and cause unexpected MissingBackpressureException (i.e., beginners don't expect them).
We try to remedy this situation in 2.x by having io.reactivex.Observable non-backpressured and the new io.reactivex.Flowable be the backpressure-enabled base reactive class.
https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#observable-and-flowable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With