Reputation: 18573
Can anyone explain the reason behind the name? Observable and Observer is obvious, but I don't understand why it's called a Subject?
Upvotes: 6
Views: 444
Reputation: 29786
I suspect the Rx team chose that name within a moment's thought because it is intended to play the same role as the Subject in the original observer pattern.
Although Subject implements both IObservable<T>
and IObserver<T>
, it is for its Observable qualities it is named.
It was the authors of the original pattern that chose it for the dictionary definition, because it is the subject that is being observed.
Upvotes: 10
Reputation: 102753
I think the dictionary definition points in the right direction: "the person or thing that is being discussed or described".
Remember, an ISubject
is simply by definition an interface that is both observable and observer. In that sense, a Subject
instance is a sort of conversation hub, which other objects can send messages to, and/or or receive messages from. But ISubject is also generic, so the messages in the conversation are restricted to objects of the generic type. Both of those senses make an ISubject
instance like "a thing that is being discussed".
Upvotes: 2