๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

Programming Concepts Intermediate

What is Observer Pattern?

A design pattern where an object (subject) maintains a list of dependents (observers) that are notified automatically of state changes.

The Observer pattern establishes a one-to-many dependency between objects. When the subject changes state, all registered observers are notified and updated automatically. This decouples the subject from its observers โ€” the subject doesn't need to know what the observers do with the notification. Examples include event listeners in JavaScript (addEventListener), pub/sub messaging, reactive streams (RxJS), and MVC frameworks where views observe model changes. Variants include push (subject sends data with notification) and pull (observers query the subject after notification). The pattern is fundamental to reactive programming and event-driven systems.

Related Terms

Stack
A data structure that follows Last-In-First-Out (LIFO) ordering, where elements are added and removed from the same end (top).
Hash Table
A data structure that maps keys to values using a hash function, providing average O(1) time complexity for lookups, insertions, and deletions.
Composition over Inheritance
A design principle favoring object composition (has-a relationships) over class inheritance (is-a relationships) for code reuse.
Functional Programming
A programming paradigm that treats computation as the evaluation of mathematical functions, avoiding state changes and mutable data.
Memoization
An optimization technique that caches function results for given inputs, avoiding redundant computations for repeated calls.
DRY (Don't Repeat Yourself)
A software development principle that aims to reduce code duplication by abstracting common patterns into reusable components.
View All Programming Concepts Terms โ†’