I'll be honest, I don't see a whole lot wrong with the code sample you listed--assuming it's just a handful of cases like that. There are a few ways you can change the code that may or may not make the resulting code more readable or the intent more clear.
One example is to separate the common clause in the if statement from the rest of the code like this:
if (wasCheckedBefore(entity.name)) {
if (entity.isSomething) showSomeMessageToUser(entity.name)
if (entity.isSomethingElse) showSomeMessageToUser(entity.name)
if (entity.isSomethingSomethinElse) showSomeMessageToUser(entity.name)
}
Another option is to have an enum type parameter to do a switch statement:
if (not wasCheckedBefore(entity.name)) return
switch(entity.type) {
case type.something:
showSomeMessageToUser(entity.name)
case type.somethingElse:
showSomeMessageToUser(entity.name)
case type.somethingSomethingElse:
showSomeMessageToUser(entity.name)
}
Or extending that concept you can simply pass the type into the method so it really becomes shorter and the complexity moved to the showSomeMessageToUser function:
if (wasCheckedBefore(entity.name)) {
showSomeMessageToUser(entity.type, entity.name)
}
The bottom line is that none of this is functionally any better than the other. It's just shuffling the logic around. The question is whether any of these approaches make the intent of the code more prevalent. If not, let sleeping dogs lie.
showSomeMessageToUser(entity.name)I'm assuming the message is different?if(wasCheckedBefore(enty.name))and still have the individualif(enitity.isSomething) showSomeMessageToUser(entity.name)inside. That may be subjectively better in terms of readability, but it also might not. If you are going to make a fundamental change at least do something to make the intent more clear. Another option is to have anentity.Typebe anenumso then you can do a switch statement. Again, whether it's better or not is subjective.