观察者模式的反面是什么? [英] What is the opposite of the observer pattern?

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

问题描述

据我所知,观察者模式允许多个观察者监视单个主题.是否有相反情况的模式?是否有一种模式可以让单个观察者监视多个主体并在其中任何一个引发通知事件时做出响应?

As I understand it, the observer pattern allows for multiple observers to monitor a single subject. Is there a pattern for the opposite scenario? Is there a pattern for a single observer that monitors several subjects and responds when any one of them raises, say, a Notify event?

推荐答案

观察者模式仍然可以使用:只需将相同的对象寄存器作为许多被监视对象的观察者即可.您可能希望通知"事件接收某种观察对象标识符(this"指针、唯一 ID 号等),以便观察者对象可以选择适合报告事件的对象的操作.

The Observer pattern can still be used: just have the same object register as an observer to many monitored objects. You'll probably want the "Notify" event to receive some kind of observed-object identifier (the "this" pointer, a unique id number etc) so that the observer object can choose an action appropriate to the object reporting the event.

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

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