且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IObserver向IObservable添加新对象

更新时间:2023-12-04 10:00:34

为此,创建新IObserver 对象的IObserver 对象将需要访问它的IObservable 对象实例.已订阅.是否如此是实现细节.

我认为这样做没有什么错,尽管这似乎有些奇怪.
To do that, the IObserver object creating the new IObserver object will need to have access to the instance of the IObservable object it''s subscribed to. Whether that''s so is an implementation detail.

I don''t think there''s anything wrong in doing that, although it does seem a little odd.



IObservable通常具有一个列表/数组来存储观察者,该观察者应该是观察者类型. IObserver类型具有一个将由Observable调用的函数.因此观察者实施了它.因此,当创建新对象(如果它是IObserver类型)时,可以将其添加到Observable中,并通知新的Observer.

通知时,这取决于您如何使用新对象中的数据.

尝试,如果有疑问,您可以在此处发表评论
Hi
IObservable usually has a list/array to store the observers which should be an observer type. IObserver type has a function which will be called by the Observable. So Observers implemented it. So when you create new object if it is a IObserver type then you can add it to observable and the new Observer get notified.

It depends how you use the data in the new objects when notified.

Try and if got doubts you can post comments here