简体   繁体   English

观察者模式和主题观察者模式有什么区别

[英]What is the difference between the Observer and Subject-Observer patterns

While watching some videos on Channel 9 about the Reactive Extensions for .NET, someone asked whether the Reactive Extensions library is an implementation of the Observer pattern. 在观看第9频道上有关.NET的Reactive Extensions的一些视频时,有人问Reactive Extensions库是否是Observer模式的实现。 The presenter then went on to answer by saying that the library is an implementation of the Subject Observer pattern. 然后,演示者继续回答,说该库是主题观察者模式的实现。 This leads me to believe that there is possibly a difference between the two patterns. 这使我相信两种模式之间可能存在差异。

Is there a difference between these two patterns? 这两种模式之间有区别吗? If so, what is the difference. 如果是这样,有什么区别。 Links to articles will be helpful too. 文章链接也将有所帮助。

From the GoF book, the Observer pattern is illustrated by using Subject and Observer. 在GoF书中,通过使用Subject和Observer来说明Observer模式。 The Subject holds a list of Observers and notifies them of any state change (usually by calling their "notify" method). 主题保存一个观察者列表,并将状态更改通知它们(通常通过调用其“ notify”方法)。

I wouldn't know what they would be talking about but that's basically it. 我不知道他们在说什么,但基本上就是这样。

Wiki on Observer Pattern . Wiki上的观察者模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM