The approach you take is most likely not what you ultimately want to do. I highly recommend that you read about the Team Template , as this is most likely what you are trying to do.
PS. The Wikipedia article contains several complex examples. In short, your Command objects can have names, and you can easily have a map of Command objects that you can search by name. The real power is that you donβt have a huge switch or something like that. Instead, you simply pass the command you want to execute, and it knows exactly what to do.
If the OOP approach is not suitable for you, then this exercise is for you to come up with a declarative solution.
I believe that you can define a user-defined attribute (UDA) with the name, say, command , and use it to annotate each function that you want to process as a βcommandβ, and then you can use compilation like what Adam does in in your example, to configure everything so that you can perform these functions when necessary. You may have a CommandDelegate[string] map, where CommandDelegate is just void delegate() or similar ...
source share