What is the opposite of the observer pattern?

后端 未结 5 1661
一向
一向 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:12

    Yes. It is just another application of the observer pattern.

    The Observer adds itself to many Subjects. If you want the same action to be performed no matter Which subject you're observing then this is exactly the same as the Observer pattern you are using.

    If you want a separate action depending on which Subject triggered the event then you can use the Action parameter that is passed into the Observer's ActionPerformed method to help determine which subject triggered the event. (these names may change depending on your language or library of choice)

提交回复
热议问题