In the following (paraphrased) code, I am checking various conditions, updating them, and scheduling a single notification regardless of the number of changed conditions. If none of the conditions are changed, no notification should go out. In addition, there is one special condition that does not trigger a notification if it changes.
public bool Update() {
bool shouldNotify = false;
if (SpecialConditionChanged())
UpdateSpecialCondition();
if (Condition1Changed()) {
UpdateCondition1();
shouldNotify = true;
}
if (Condition2Changed()) {
UpdateCondition2();
shouldNotify = true;
}
...
return shouldNotify;
}
This code works, but it is very verbose and repetitive having to set the flag every time. I am asking if there is a more elegant or efficient solution. Something that will return false if either zero conditions or only the special condition have changed, but will return true if any of the remaining conditions have changed.
I've thought about using a bool[] (just as verbose); I've thought about using a counter (just as repetitive); I've thought about adding an extra if that ors all the conditions together to change the boolean once (there are a lot of conditions), but nothing I've thought about is any cleaner than this version.
Am I missing something that could make this look or work better?