Git Product home page Git Product logo

cse306-observer's Introduction

CSE306 Observer Design Pattern

Chenxu.Fu15 1509284

Environment Setup

  1. The program requires Node.js and NPM(or Yarn) as packager manager installed.

  2. From root directory, run cd original and npm install(or yarn install)

  3. From root directory, run cd observer and npm install(or yarn install)

Get started with Original version

  1. From root directory, run cd original and npm start(or yarn start)

  2. Server will start on port 6395(default), and browser will open automatically on http://localhost:8080

Improved version using Observer Design Pattern

  1. From root directory, run cd observer and npm start(or yarn start)

  2. Server will start on port 6396(default), and browser will open automatically on http://localhost:8081

Principles

Observer Design Pattern decouples different types of objects in terms of Observer and Subject(Observable), defining a one-to-many dependencies, and when the subject changes, all its observers will be updated automatically.

As real world examples, user can subscribe a newsletter, a podcast or chatroom. When new content is added, instead of users actively polling for changes(interval refresh), the users can be notified by the server directly.

Web example

The detailed webpage example makes use of WebSocket to implement the Observer Design Pattern. In this example, server and client act as both Observer and Subject. When user publishes a new message, The server observes the event emitted from client, and then dispatch the event to other clients. The other clients will observe for events emitted from server and be updated automatically.

Principle.js

The code abstracts the basic principle of Observer Design Pattern, the Subject(newsletter) can subscribe and unsubscribe multiple Observers(users) by updating the subscription list. When the Subject dispatch an event, it will loop through the subscription list and notify them.

ouput

Full code of original project

U-CIRCLE - CSE208 Group Project

Online product link

U-CIRCLE

cse306-observer's People

Contributors

fuchenxu2008 avatar

Stargazers

Han Wenqi 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.