JAVA SCRIPT DESIGN PATTERNS

The Observer pattern provides a way to notify multiple subscribers on single event

Observer Pattern

The observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods

Lets say we run a ecommerce

Lets say when some one puts an order on our website we want to perform certain actions like notify the supplier , notify the customer thorugh email and sms

Event : When someone puts the order

Subscribers : 1. notify supplier 2. Send customer email 3. send customer sms

--

--

JAVA SCRIPT DESIGN PATTERNS

The Proxy pattern provides a proxy (duplicate ) object for another object and controls access to this other object

let see it by an example
lets say we have a user object like below

const user = {
userName:"neerajdana",
email:"neerajdana9@gmail.com",
age:32
}

now lets say we want to apply some constrains or validations when someone modify the object values as follows

  1. The username length should be min 4 and max 10
  2. The userName should always be saved in lower Case
  3. The email should be proper email
  4. The age should be number

But right now we can set the values directly and no one will stop us from doing so

This is where proxy pattern comes handy
so rather then exposing the subject (user object) directly we will create a proxy object and then expose that proxy object lets see it

--

--

Neeraj Dana

Neeraj Dana

Experienced Software Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Angular,React,React-Native,