clean-code-javascript icon indicating copy to clipboard operation
clean-code-javascript copied to clipboard

Add info to "Avoid conditionals" about smelly code and open/closed principle

Open Tarabass opened this issue 8 years ago • 1 comments

I don't think that the provided info about why not use switches in this section is complete. Maybe we should add info about smelly code, the strategy pattern and open/closed principles.

In this speak/presentation it is all made clear why not using switches. And it has not so much to do with functions doing on thing, but more about the open/closed principle and that with adding/removing/editing one case you just "touched" all cases in the switch and all have to be tested again.

Also he added a example using the strategy pattern to refactor the switch without violating the "open/closed principle". I like that example very much.

Tarabass avatar Jan 11 '17 07:01 Tarabass

Up for a PR if you have time? 😄

ryanmcdermott avatar Jan 16 '17 19:01 ryanmcdermott