can an observer observe multiple observables?

前端 未结 5 1752
南笙
南笙 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 16:54

    I subscribe to the idea that 1 class performs 1 core task. If it were me, I would build an observer interface, create multiple observer implementations, and manage all of those observers with some ObserverManager class.

    Doing it this way will separate all of your business concerns, and will afford a finer level of granularity for testing.

    Unless the "changes of many other operations" can be typified as the same kind of observable "change." At that point the the single observer makes sense.

提交回复
热议问题