对“观察者模式”和“订阅发布模式”的理解

具体含义不介绍,只谈谈自己的理解,如有理解错误请指出:


对比图
  • 订阅发布模式比观察者模式多一步,叫做Broker(经纪人)
  • 观察者模式的实际应用:Spring的ApplicationEvent和ApplicationListener

Spring官方文档 Event handling in the ApplicationContext is provided through the ApplicationEvent class and the ApplicationListener interface. If a bean that implements the ApplicationListener interface is deployed into the context, every time an ApplicationEvent gets published to the ApplicationContext, that bean is notified. Essentially, this is the standard Observer design pattern.

  • 订阅发布模式的实际应用:STOMP+WebSocket

设计模式没有好坏之分,而是要根据实际应用选择相应的模式。

你可能感兴趣的:(对“观察者模式”和“订阅发布模式”的理解)