© Dmitri Nesteruk 2018
Dmitri NesterukDesign Patterns in Modern C++https://doi.org/10.1007/978-1-4842-3603-1_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 come 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:

1   struct Person ...

Get Design Patterns in Modern C++: 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.