
One of my favorite design patterns is the Observer pattern! (C# events)
It's one of my favorites because it allows me to achieve my favorite word in all of programming, decoupling!
If you want to write high quality code then that word should be on your mind constantly. The more decoupled your code is the easier it is to keep working on that codebase.
And the observer pattern (events) allow you to decouple your code, the main way is decoupling UI from the Logic class. For example you have some Health System script, it should NOT be tightly coupled with some kind of Health Bar UI script. The Health System should work whether or not a UI exists, it should not care about it.
So in practical terms the HealthSystem script should fire off some kind of OnHealthChanged event, and the UI script hooks onto that event and updates the visual Health Bar. That way the HealthSystem is completly decoupled so when you're working on the Health System the only thing you need to keep in your brain is just the Health System and nothing else.
Same thing for separating visuals from logic, they should be as decoupled as possible.
If you can play your game without visuals at all then that codebase is likely very easy to work with.

English



