What is the opposite of the observer pattern?

后端 未结 5 1658
一向
一向 2020-12-05 07:26

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

5条回答
  •  天命终不由人
    2020-12-05 08:19

    Also consider related Mediator pattern.

    Mediator pattern defines an object that encapsulates how a set of objects interact (Wikipedia)

    More info here: http://sourcemaking.com/design_patterns/mediator

    I also very like @CDC's answer on Mediator Vs Observer Object-Oriented Design Patterns:

    The Observer pattern: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

    The Mediator pattern: Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.

提交回复
热议问题