Today I Learned - Rocky Kev

TIL Observer Pattern

POSTED ON:

TAGS:

Observer Pattern

Observer is a behavioral design pattern in which objects get information about any events happening to the object they are observing. The observer pattern defines a subscriber method, which will update every object that is subscribed to itself, making sure every subscriber gets the latest update.

An example of an observer in our daily life would be subscribing to a newsletter. The moment you join the mailing list you are notified when there is a new publication.

Use this pattern when changes on one object may require updating other objects, and the actual set of objects is unknown or changes dynamically.

Via Design Patterns for Web Development


Related TILs

Tagged:

TIL a bunch of new functional programming words

It's so funny seeing developers re-invent functional programming paradigms. We really need to teach this stuff better.

TIL Cleaner data structures

Avoid unnecessary contexts, optional chaining, better error handling, avoid using flags

TIL Cleaner Functions

tl;dr - Limit the number of arguments, Avoid executing multiple actions in a function, Avoid mutation, Avoiding non-negatives, Return Early