具体含义不介绍,只谈谈自己的理解,如有理解错误请指出:
对比图
- 订阅发布模式比观察者模式多一步,叫做Broker(经纪人)
- 观察者模式的实际应用:Spring的ApplicationEvent和ApplicationListener
Spring官方文档 Event handling in the
ApplicationContext
is provided through theApplicationEvent
class and theApplicationListener
interface. If a bean that implements theApplicationListener
interface is deployed into the context, every time anApplicationEvent
gets published to theApplicationContext
, that bean is notified. Essentially, this is the standard Observer design pattern.
- 订阅发布模式的实际应用:STOMP+WebSocket
设计模式没有好坏之分,而是要根据实际应用选择相应的模式。
网友评论