can an observer observe multiple observables?

前端 未结 5 1733
南笙
南笙 2021-02-10 16:14

trying to find an example of this, it\'s possible that I am not going the right way around it, or that my mind has over simplified the concept of the observer pattern.

I

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-10 17:00

    I think it's really important to remember that design patterns are suggestions and not absolutes. If they can be modified to better fit your needs then they should.

    And yes in this case it can most definitely be done. Your observers will simply need to register with more than one observable object.

    When one of your observable objects will notify it's observers it will simply loop on a list of references to tell them to update. It really doesn't matter if these references are shared with other observable objects.

提交回复
热议问题