We have some states, depending on a window that is currently active:public enum LoginState{    NONE,    LOGGIN_IN,    LOGIN_SUCCESS,    LOGIN_FAILED}public enum LobbyState{    NONE,    FINDING_MATCH,    FOUND_MATCH}I need to notify the listeners about state changes through something like: UIManager.Instance.Notify(LobbyState.FINDING_MATCH)so the subscribers get notified about the change. The problem with this approach is that I have multiple State types like LoginState, LobbyState, MatchState and I need to be able to subscribe only to specific ones. For instance - I need to listen for login changes in lobby, but I don't need to listen in login window for lobby changes.First thing I came up with is that I made a global Event System where I register state listeners and invoke changes to subscribers.For example:public interface StateListener<T>{    void OnStateChanged(T state);}which can be used with different state types like:class Lobby : StateListener<MatchState>, StateListener<ProfileState> {    public Lobby(){        EventSystem.Register(this); // here's the issue no. 1        EventSystem.Register<MatchState>(this); // or this        EventSystem.Register<ProfileState>(this); // or this        ...    }    void OnStateChanged(MatchState state){        switch(state) { // do things }    }    void OnStateChanged(ProfileState state){        switch(state) { // do things }    }}The problem with this approach is that it becomes a mess when I register different listeners as you can see in above's class constructor. Also, I have to provide a generic type twice (in class declaration and in the constructor).I could make 10 different containers for all state types like:List<StateListener<MatchState>> matchStateListeners;List<StateListener<LoginState>> loginStateListeners;...public void RegisterListener(StateListener<MatchState> listener){ // add}public void RegisterListener(StateListener<LoginState> listener){ // add}...But then, it becomes a real mess.Is there a better approach to achieve something like this?
How should I code a multi-type observer pattern?
c#;design patterns;state;observer pattern