IObserver向IObservable添加新对象 [英] IObserver adding new object to IObservable

查看:89
本文介绍了IObserver向IObservable添加新对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过以下方式实现:

我有一个IObservable对象,它有几个IObserver对象.
这些IObserver对象中的一个(或多个)是否可以创建一个新对象(从另一个类然后从其自身),但是可以使这个新对象同时也是我所拥有的IObservable的观察者?
我不知道如何编写代码并使新对象订阅到原始IObservable.

:〜

Is it by any means possible to:

I have an object that is IObservable and it has several IObserver object.
Can one (or more) of these IObserver objects create a new object (from an other class then itself) but make this new object also observer of the IObservable i have?
I wouldnt know how to write the code and get the new object subscribed to the original IObservable.

:~

推荐答案

为此,创建新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


这篇关于IObserver向IObservable添加新对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆