I need to link three classes, Portal, WaveManager and TimeManager, so that when a condition is satisfied in Portal, TimeManager.SlowTime() and WaveManager.SpeedUpSpawn() are executed. Events seem to me the most obvious design solution, but I always doubt about who should be responsible for the addition of the observers. These are the two options I can imagine:
A. TimeManager and WaveManager add themselves as observers to the event in Portal:
B. The observer additions are made by an instance of some intermediary class:
Portal is a minor, peripheral class in the application, as is WaveManager compared to TimeManager. Even though it is not called from many places, it feels wrong to force TimeManager to know a minor class like Portal as I do in option A, just in order to be able to add itself as a listener to the event.
Option B on the other hand seems too convoluted, and it is not obvious which class in my code should be in charge of those additions. I would probably need to add ad hoc classes and functionalities for that purpose.
What is generally the approach to the addition of observers? Is it frequent or good practice to make the observers add themselves as observers? Are there other design options other than the two I proposed?


I believe
Portalis here a subject. So it looks likePortalshould add/register new observers.Let me show some example of implementation of an observer pattern via C#:
These are classes related to observer:
and its concrete implementation:
These are classes related to subject:
and its concrete implementation:
And then you can call the above code like this:
OUTPUT: