Giter VIP home page Giter VIP logo

observer-pattern's Introduction

Observer 模式

在观察者模式(Observer Pattern)中,一个目标对象管理所有相依于它的观察者对象,并且在它本身的状态改变时主动发出通知。这通常透过呼叫各观察者所提供的方法来实现。此种模式通常被用来实时事件处理系统。

观察者模式有四个角色:

  • ISubject:抽象被观察者,将所有的观察这放入集合中,提供以下接口:
    • add_observer():添加
    • remove_observer():删除
    • notify_observers():通知
  • Subject:具体被观察者,将有关状态存入具体观察者对象,在具体主题的内部状态发生改变时,给所有注册过的观察者发生通知
  • IObserver:抽象观察者,提供「更新接口」的定义
  • Observer:具体观察者,实现抽象观察者定义的「更新接口」,以便在的到主题更改通知时更新自身的状态

Observer

观察者模式也常被称为「发布/订阅(Publish / Subscribe)」模式。

参考资料


observer-pattern's People

Contributors

tomsawyer404 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.