Pattern strategies and optimizations
If you decide the original Observer pattern is right for a portion, or the entirety, of your project, you’ll need more clarity in three key areas:
- Choosing the kind of information the subject sends to observers, which is commonly referred to as the communication strategy
- Specifying different events that subjects can send out and choosing which events your observers listen for and act on
- Managing object references and memory leaks when subjects or observers are destroyed or disabled
While I’ve marked this section as pattern variations and optimizations, incorporating these three topics into your design pattern code is mandatory if you want an efficient, scalable, and safe project.
I can’t stress this enough, especially the object cleanup; ghost objects and memory leaks are no joke and are extremely hard to debug in the decoupled subject-listener structure.