Observer Design Pattern vs “Listeners”

前端 未结 3 1497
时光取名叫无心
时光取名叫无心 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 10:42

    Whether the term "listener" refers to the Observer pattern or not will depend upon the context. For example, Java Swing's "Event Listeners" are part of an Observer pattern implementation while .Net "Trace Listeners" are not.

    It isn't uncommon for framework authors to assign different names to components participating in a given pattern implementation, but the official pattern names are generally used when discussing the patterns themselves.

    Concerning design, the implementation of a given pattern will often be influenced by the language and platform being used. As such, a particular implementation of the Observer pattern within a given framework (which may happen to use the term "listener" to describe the role of the ConcreteObserver) might differ slightly from that described in the Design Patterns book.

提交回复
热议问题