I don't know if the title makes sense, but basically I am wondering people's opinions on whether to calculate public members whenever they have to be changed, or as soon as they are accessed?
Say you have a class like CustomCollection
, that has a property called Count
. Should Count
be updated for each Add
, Remove
, etc operations, or should it just be calculated at the time it's accessed?
Keeping up-to-date seems intuitive, but then you wonder, how often people call Add
, Remove
, etc vs .Count
.
Also is there a hybrid version where you can cache it when the property is accessed? I think that would require another variable to be updated, right?