How to parameterize the call Signal?

21 views
Skip to first unread message

Lei Zhang

unread,
May 2, 2018, 2:19:03 AM5/2/18
to StrangeIoC

Hi,

I’m new to StrangeIoC. Quick question - is there a particular way to dispatch Signal like:

Current usage:

    public void DispathSignal (string signalName) {
        switch (signalName) {
            case "signal1":
                signal1.Dispatch ();
                break;
            case "signal2":
                signal2.Dispatch ();
                break;
            case "signal3":
                signal3.Dispatch ();
                break;
            case "signal4":
                signal4.Dispatch ();
                break;
        }
    }


Replace with:

    public void DispathSignal(string signalName)
    {
        (Signal)signalName.Dispatch();
    }

or like The dispatcher extension:

   dispatcher.Dispatch(AttackEvent.FIRE_MISSILE);





wcorwin

unread,
May 2, 2018, 4:21:38 PM5/2/18
to StrangeIoC
So this isn't terribly strange specific, although if I saw an ugly switch like that it would raise a red flag. You're essentially recreating a basic map, so I suggest either making use of a hashmap(dictionary in c#), or potentially looking at extending our binder class, which is basically just a hashmap. And just to be clear, I think you probably have a simple architectural issue here if you're passing around names of things to call.
Reply all
Reply to author
Forward
0 new messages