Spotting use cases for the Observer pattern
The Observer pattern is a versatile behavioral pattern. Since its core intent is to promote loose coupling, or total decoupling, of classes, we can implement it in a variety of systems in our games. In this section, we will see some applications of this pattern, but they are not the only places where we can use the Observer pattern. Keep in mind its core features and you can see that it can be used in different cases, especially when you want to communicate between two indirectly related objects or if you want objects to be notified about changes in the state of another object.
A good use case for the Observer pattern is the Graphical User Interface (GUI) and especially Heads-Up Display (HUD) elements. Usually, when we create games, the HUD elements are implemented separately from the game world’s elements. For instance, in Godot Engine, it’s common to have a CanvasLayer
node holding the HUD and other GUI elements as its...