Practical Patterns – Building a Temperature Publisher
Design patterns are tools for solving common problems. So far, we have covered a few design patterns in this book, such as the Command and Adapter patterns. In this chapter, we will go over the Observer pattern and apply it to a common problem in embedded systems – handling temperature readings in different parts of the system.
We will start by looking at the Observer pattern and how it can be implemented at runtime. This pattern is particularly useful when multiple components need to react to changes in data from a central source. Imagine a temperature sensor in an embedded device that reports changes to multiple listeners. This could be part of a smart thermostat, an industrial machine monitor, or an HVAC control board – each with components such as a screen, a logger, or a fan controller that react to temperature updates.
Next, we will transition to a compile-time implementation of the same pattern...