Discussion on: When DRY Doesn't Work, Go WET

poisonousjohn profile image
Ivan Fateev

Yes, the example violates the single responsibility principle. If some code abstraction is doing some branching depending on some boolean flag, it's the first sign of a single responsibility principle violation.

So in this case, when you've got new requirements and understood that you need to do different things, just split the code up for different entities (components, whatever you call them). Each should do just a single thing.

Branching should be done outside of those abstractions, and should be clear and explicit.

Otherwise, later, when you read the code, you will need to go deep down to the abstractions level just ot understand that the flag A causes N branching cases.