Observer Design Pattern vs “Listeners”

前端 未结 3 1488
时光取名叫无心
时光取名叫无心 2020-12-07 10:07

It seems to me that the Observer design pattern as described in GOF is really the same thing as Listeners found in various toolkits. Is there a difference between the concep

3条回答
  •  再見小時候
    2020-12-07 11:04

    There's a two-way nature to the description of Observer in Design Patterns by Gamma et. al. (GoF).

    In their description of Observer, one of the ConcreteObservers might signal a change to its Subject. The Subject, which holds a list of all ConcreteObservers, then notifies its list. All ConcreteObservers, including the prime mover, then react as appropriate.

    The common implementations of Listeners seem to all react to events from outside.

    So, I would say that the Listener is a less-generalized case of an Observer.

提交回复
热议问题