链接观察者/可观察模式 [英] Chaining of observer/observable pattern

查看:203
本文介绍了链接观察者/可观察模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有形成复合观察者/可观察的设计模式?

我的意思是我有一个可观察的 A 通知其监听者一些变化。

每个监听器也是一个可观察的并通知自己的监听器(在一些动作上,它是通过第一个可观察的通知触发的动作)。

这是链接观察者/观察者可以设计或者是否有标准模式?

解决方案

对于你提到的链接,我观察者模式的目的是,当对象的状态发生变化时,它会通知感兴趣的方(听众/观察者)关于变化,并且让听众根据状态变化作出反应。



如果听众的状态变化是按照设计观察到的,其他有兴趣的方面,我没有看到任何理由为什么我不能使用观察者模式来发布事件。



然而,我只是另一个观察员可观察的关系。没有特殊的链接发生。



有点OT:更适合被称为链接的东西是:观察对象O向监听器A发送事件E ,而A会将事件传播给另一个听众B.但是从逻辑上讲,他们都在听从O发起的事件。这种链接可以通过使用装饰器模式来完成。


Is there a design pattern that forms a "composite" observer/observable?
I mean I have an observable A that notifies its listeners on some change.
Each listener is also an observable and notifies its own listener (on some action it did which action was triggered by notification of the first observable).
Is this "chaining" of observers/observables ok as design or is there a standard pattern for this?

解决方案

For the chaining you mentioned, I don't see any difference.

The aim of Observer pattern is, when the state of an object is changed, it notify interested parties (listener/observer) about the change and let the listener react according to the state change.

If the state change of the listener is, by design, observed by other interested parties, I don't see any reason why I can't use observer pattern for the publishing the event.

However it is simply another observer-observable relationship. There is no special "chaining" happening.

A bit OT: something that is more appropriate to be called chaining is: An observed object O send an event E to listener A, and A will propagate the event to another listener B. However logically they are all listening to event originated from O. Such kind of "chaining" you can be done by using decorator pattern.

这篇关于链接观察者/可观察模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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