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

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

问题描述

据我了解,观察者模式允许多个观察者监视单个主题。是否有相反情况的模式?单个观察者是否有模式监视多个主题,并在任何一个观察者提出Notify事件时作出响应?

解决方案

p>仍然可以使用Observer模式:只有与许多监视对象的观察者具有相同的对象注册。您可能希望通知事件接收某种观察对象标识符(this指针,唯一的ID号等),以便观察者对象可以选择适合报告事件的对象的操作。 / p>

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?

解决方案

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天全站免登陆