- The observer pattern, also referred to as the publish/subscribe pattern, is a design pattern where an object (called the subject or observable), will maintain a list of “dependents” called observers.
- This video is a good summary of the Observer pattern chapter in the book Head First Design Patterns book.
Redux: A use case for the observer pattern
If you work in the world of React, you have probably dealt with Redux to manage the state of your application.
- Redux is an implementation of the observer pattern.
- This method “pushes” new subscribers to the array
const subscribe = (listener) = (
Remember that subscribe is called in the componentDidMount method which fires immediately after the component mounts.
- Every author tends to make his own particular pattern form, but certain pattern forms have become more well-known.
- The idea is that you have a body of patterns with a structure that leads you from pattern to pattern.
- Once you look at two sets of patterns you realize hardly ever do two patterns authors use the same form.
- Many people see Christopher Alexander’s A Pattern Language (APL) as an important influence in the patterns world.
- The desire is reinforced by the chunking that patterns are about – a reader should only have to read that one pattern to understand the pattern.
I’ve spent a lot of my writing energy writing
patterns. From time to time I get asked questions about why I do
that and what makes a good pattern. This is a brief article about
how I look at patterns with my suggestions for people who are
interested in writing patterns themselves.
Continue reading “Writing Software Patterns”