Don't use switch statements or chained if-else statements. While they certainly can be useful in some situations, the majority of cases I see it in use signals a place where that logic needs to be extracted behind an interface, where each case is an implementation of that interface. The presence of a switch is a major code-smell when it comes to building maintainable or modular software.
Ah, I had no idea there was a name for this pattern, but that's exactly it! I see references to GoF everywhere, and I usually find I'm actually doing a bunch of these patterns myself already when I see it. Maybe I should actually read that book sometime...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Don't use
switch
statements or chainedif-else
statements. While they certainly can be useful in some situations, the majority of cases I see it in use signals a place where that logic needs to be extracted behind an interface, where eachcase
is an implementation of that interface. The presence of a switch is a major code-smell when it comes to building maintainable or modular software.So basically a chain-of-responsibility pattern. I can get behind that.
I think we can adapt Craig Zerouni's quote a bit to give us a nice rule:
Ah, I had no idea there was a name for this pattern, but that's exactly it! I see references to GoF everywhere, and I usually find I'm actually doing a bunch of these patterns myself already when I see it. Maybe I should actually read that book sometime...