Most OO guides say not to store things in instance variables if they can be easily calculated, because the state might become inconsistent, and there is more code to maintain. I am trying to come up with a general guideline of how to decide this issue.
For example, if I have a simple object like Rectangle, I could store only the side lengths, or I could also store some easily calculated values like Area and Perimeter, which would be updated any time a side length was changed. The area and perimeter properties (accessors) would be read-only. In a second example, more complex computations such as employee Deductions based on pay might be made. Use Instance variables or calculate whenever needed? (In all cases I would not store calculated values in a database, so that is not related to this question... Unless you mean a Data Warehouse, which throws all the relational rules out the window anyhow.)
Is there an overall outlook on how this should be decided? Are there references that actually distinguish different answers, not just make a blanket recommendation? Thank you.
In in case it makes a difference I'm using C#.
Also, I am aware of DRY (don't repeat yourself - don't duplicate code), so I am asking about a situation where the calculation is one place in the code: either in the setter for the instance variable which defines it (Sides define the Area), or in a getter for Area itself, with Area not being stored. In both cases Area will not have a setter.