I've been tasked with refactoring a console application, which is constantly running on a server and receiving messages from a service bus.
Right now, it just parses the incoming message, and based on a property, will use a switch statement to call one of many different functions (about 70 at the moment, always growing). One problem is that if a function fails, it's not retried. Not to mention just the ugliness of one giant switch statement.
I'm leaning towards using the Command Pattern to rectify this (https://scottlilly.com/c-design-patterns-the-command-pattern/), but have also considered a pub/sub pattern to handle these functions.
Anybody know what the best architecture pattern might be for this situation?
switch
). – Jan 31 '18 at 22:04execute
and nothing else, it's better than introducing a whole new interface just for one function. I tend to see that as an application of the command pattern so I think delegates are just fine as a way to implement that -- sorry if I didn't make that clear. Where I tend to find making an interface useful is that they might have a few more functions, likeundo
orredo
. Otherwise I also prefer function objects/delegates/function pointers over functionids... don't like seeing [...] – Feb 01 '18 at 18:26ITreeVisitor
-- could just be a function object which could be more easily constructed using lambdas! So I often don't like how design patterns can sometimes tempt people to implement them "by the book" this way while ignoring the language features. I just tend to take it as a given that many of these can and should be implemented with the most appropriate language features. – Feb 01 '18 at 18:28