Before Refactoring
getPersonAndIncreaseCounter(){
counter ++;
return person;
}
After Refactoring
getPerson(){
return person;
}
increaseCounter{
counter ++;
}
Benefits
You can call getPerson() as often as you like. You have a lot less to worry about.
Exception
It’s OK to change personCache in getPerson() method.