The dirty flag behavioral pattern allows you to avoid expensive operations that would just need to be done again anyway.
This is a simple pattern that really just explains how to add a bool value to your class that you can set anytime a property changes. This will let your class know that any results it may have previously calculated will need to be calculated again when they’re requested. Once the results are re-calculated, then the bool value can be cleared.
Even though this is a simple design pattern, there are some things you’ll need to consider: