The observer pattern

This is a very common design pattern and can be seen being implemented in many areas of software applications, such as (Model View Controller (MVC), event handling, and almost all GUI toolkits. If we take an example of MVC, then "View" informs all its dependents such as the controller whenever there is any change in the UI.

This design pattern is also referred to as the publisher-subscriber pattern frequently. It works on the principle of don't call us - we'll call you. The publisher, in this case, notifies all its subscribers whenever required.

Note

The observer pattern is a behavioral design pattern in which an object (a subject or publisher) maintains a list of all its dependents (an observer or subscriber) and notifies them ...

Get Apex Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.