The observer design pattern is one which is not commonly used in games, but it should be used more often by game developers as it is a very smart way to handle notifications. In the observer design pattern, a component maintains a one-to-many relationship with other components. This means when the main component changes, all the dependent components also update. Imagine a physics system. We want enemy1
and enemy2
to update as soon as the physics system updates, so we should use this pattern.
In this recipe, we will find out how easy it is to implement the observer pattern: