liveBook · Manning

Observer pattern

Also called observer design pattern

The observer pattern is a behavioral design pattern in which dependent observers register with a subject or observable and receive notifications when it changes or emits events.

How 5 Manning books explain it

Software Design for Python Programmers

A behavioral design pattern in which dependent objects are notified when an observed object's state changes.

How it is used
Supports publisher–subscriber architectures where one component produces data for independently implemented consumers.
How deep it goes
Defines Subject, Observer, notification, attachment, detachment, and state retrieval through a worked Python application and generic model.
Examples
Uses news streaming, baseball hit events, logs, statistical tables, bar charts, and a fan-club bulletin.
What you can do after
Build it from scratch by defining Subject and Observer roles, wiring subscriptions, notifying observers, and letting each observer process state independently.

Read how Software Design for Python Programmers explains observer pattern →

Microservices Patterns, Second Edition

A behavioral design pattern in which observers subscribe to notifications published by a subject whose state or activity changes.

How it is used
Separates secondary reactions to domain activity from a module’s core responsibilities.
How deep it goes
Defines subjects and observers and describes transaction behavior, but gives no implementation details.
Examples
Uses order creation triggering Notification Management to send a confirmation email.
What you can do after
Apply it to notify observers of domain changes while keeping secondary reactions outside the subject’s core responsibility.

Read how Microservices Patterns, Second Edition explains observer pattern →

Object-Oriented Software Design in C++

A design pattern that defines a one-to-many dependency so observers are notified when a subject changes state.

How it is used
Uses one publisher to distribute changing content to multiple independently implemented subscribers.
How deep it goes
Explains the one-to-many structure and C++ notification flow through Subject, Observer, attach(), detach(), and notify().
Examples
Demonstrates baseball hit events through log, graph, table, and player-specific fan-club reports.
What you can do after
Apply it by defining a Subject, an Observer update contract, subscription operations, and publisher notifications.

Read how Object-Oriented Software Design in C++ explains observer pattern →

Idiomatic Rust

The observer pattern is a behavioral design pattern in which a subject notifies registered observers about events without depending on their concrete implementations.

How it is used
Enables subjects to notify observers about events in event-processing and event-handling systems.
How deep it goes
Defines observer and observable traits, then implements registration, removal, and notification with shared and weak pointers.
Examples
Demonstrates a string-state subject notifying two named observers that print the observed state.
What you can do after
Build a Rust observer implementation with traits, registration methods, and weak references.

Read how Idiomatic Rust explains observer pattern →

Django in Action

The observer/observable pattern is a design pattern in which observers register interest in an observable and receive notifications when its state or activity changes.

How it is used
Automates side effects after ORM events, especially creating a UserProfile when a User is created.
How deep it goes
Explains registration, senders, pre/post timing, creation checks, and duplicate protection, but does not develop a general signal architecture.
Examples
Demonstrates a post_save User handler that creates a missing UserProfile across application, Admin, and fixture workflows.
What you can do after
Build it from scratch by registering a Django signal handler and safely creating a related model as a save side effect.

Read how Django in Action explains observer pattern →

Also covered in

What to know first

Related concepts

Questions about observer pattern

What is observer pattern?

The observer pattern is a behavioral design pattern in which dependent observers register with a subject or observable and receive notifications when it changes or emits events.

Which Manning books explain observer pattern?

Software Design for Python Programmers, Microservices Patterns, Second Edition, Object-Oriented Software Design in C++, Idiomatic Rust and Django in Action.

What should I know before learning observer pattern?

Manning books that teach observer pattern usually introduce design pattern, handler, Law of Demeter and coupling first.

What is the difference between observer pattern and callback?

The observer pattern is a behavioral design pattern in which dependent observers register with a subject or observable and receive notifications when it changes or emits events. A callback is a function or other callable supplied or registered with a component for invocation at a specified event, condition, or point in execution.

What is observer pattern a kind of?

Observer pattern is a kind of pattern. A pattern is a reusable approach to solving a recurring problem within a particular context.

What are the parts of observer pattern?

Observer pattern includes generic model.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.