© Dmitri Nesteruk 2022
D. NesterukDesign Patterns in Modern C++20https://doi.org/10.1007/978-1-4842-7295-4_20

20. Observer

Dmitri Nesteruk1  
(1)
St. Petersburg, Russia
 

The Observer pattern is a popular and necessary pattern, so it is surprising that, unlike other languages (e.g., C#), neither C++ nor the Standard Library comes with a ready-to-use implementation. Nonetheless, a safe, properly implemented Observer (if there can be such a thing) is a technically sophisticated construct, so in this chapter, we’ll investigate it with all its gory details.

Property Observers

People get old. It’s a fact of life. But when someone gets older by a year, we might want to congratulate them on their birthday. But how? Given a definition such as
struct Person
{
   ...

Get Design Patterns in Modern C++20: Reusable Approaches for Object-Oriented Software Design 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.