should the Observer Pattern include some infinite loop detection?

后端 未结 6 1936
我在风中等你
我在风中等你 2021-01-03 09:23

Quickly going through the GoF and the Head First Design Patterns book, it seems like there is no mentioning of infinite loop detection and handling for the Observer pattern?

6条回答
  •  囚心锁ツ
    2021-01-03 09:35

    As @Matthew points out this would be a case of poor design and you ought to catch that during design and solve it by improving the design, not adding more complexity to the code. Specifically, I think it would be a sign that classes lack cohesion, that responsibilities are spread out through the various classes rather than properly assigned to a single class or small set of cooperating classes. Properly applied to a good architectural design the Observer pattern ought not need any special handling to prevent the infinite generation of callbacks.

提交回复
热议问题