In Intro to Rx the following is said:
BehaviorSubjects are often associated with class properties. As they always have a value and can provide change notifications, they could be candidates for backing fields to properties.
However I couldn't really find a clear example of how to do this.
If I understand this correctly, something like this is proposed:
private BehaviorSubject<int> _myNumber = new BehaviorSubject<int>(0);
public int MyNumber
{
get { return _myNumber.Value; } // optional
set { _myNumber.OnNext(value); }
}
public IObservable MyNumbers
{
get { return _myNumber.AsObservable(); }
}
I have several questions about this:
- Is this indeed what is being proposed?
- Is there a general name for this pattern, something I could Google further? As I didn't know what to call it and my searches came up short.
- Is this considered good practice? Or are there better ways of doing the same (i.e. kind of creating an observable field)?
- What would you suggest as a naming convention for this?