Summary
There you have it – the Observer pattern simplified! (I’m only sort of joking). This was another big content dump, but running with the easiest plug-and-play solution without understanding the underlying foundation is a dangerous game. Luckily, you now have the necessary information to make the best decision for your own projects.
Remember, the Observer pattern sends change notifications from subjects to all subscribed observers. Subjects and observers are decoupled, meaning each observer decides how to react to subject changes. C# has built-in types specific to the Observer pattern – delegate
, event
, EventHandler
, and Action
, while Unity has built-in types specific to the Observer pattern – UnityEvent
and UnityAction
. As we’ve seen, C# types are exponentially more performant than Unity types.
In the next chapter, we’ll tackle object behavior with the State pattern – specifically, how to create objects that can alter...