title: raise flag if attribute is changed results in too many properties?
body: <p>For my application I have an object which has some set of attributes. One set of attributes, the parameters, can be accessed and adjusted by the user. The other set of attributes, the outputs, should be accessible by the user but are calculated using internal methods. Furthermore, if any of the parameter attributes are adjusted the outputs must also be re-calculated from the internal methods and adjusted accordingly. However, as these calculations may be costly I do not want to needlessly run them unless (or until) they are requested.</p>
  
  <p>Currently I can implement this by making each "parameter" attribute a property and including a <code>self.calculated</code> flag which is raised whenever any of the parameters are changed and also making each "output" attribute a property which checks the <code>self.calculated</code> flag and accordingly either returns the output directly if no calculation is needed or performs the calculation, lowers the flag, and returns the output.</p>
  
  <p>See code</p>
  
  <pre><code>class Rectangle(object):
  
      def __init__(self, length=1, width=1):
          self._length = length
          self._width = width
          self._area = self.calc_area()
          self._perim = self.calc_perim()
          self.calculated = True
  
      @property
      def length(self):
          return self._length
  
      @length.setter
      def length(self, value):
          if value != self._length:
              self._length = value
              self.calculated = False
  
      @property
      def width(self):
          return self._width
  
      @width.setter
      def width(self, value):
          if value != self._width:
              self._width = value
              self.calculated = False
  
      @property
      def area(self):
          if self.calculated is True:
              return self._area
          else:
              self.recalculate()
              return self._area
  
      @property
      def perim(self):
          if self.calculated is True:
              return self._perim
          else:
              self.recalculate()
              return self._perim
  
      def calc_area(self):
          return self.length * self.width
  
      def calc_perim(self):
          return 2 * (self.length + self.width)
  
      def recalculate(self):
          self._area = self.calc_area()
          self._perim = self.calc_perim()
          self.calculated = True
  
      def double_width(self):
          self.width = 2 * self.width
  </code></pre>
  
  <p>This gives the desired behavior but seems like an excessive proliferation of properties which would be especially problematic if there got to be a large number of parameters and outputs.</p>
  
  <p>Is there a cleaner way to implement this attribute change/recalculation structure? I have found a couple of posts where a solution is presented involving writing a <code>__setattr__</code> method for the class but I'm not sure if that would be straight forward to implement in my since the behavior should be different depending on the particular attribute being set. I guess this could be handled with a check in the <code>__setattr__</code> method about whether the attribute is a parameter or output...</p>
  
  <p><a href="https://stackoverflow.com/questions/18812341/decorating-a-class-to-monitor-attribute-changes">Decorating a class to monitor attribute changes</a></p>
  
  <p><a href="https://stackoverflow.com/questions/41330968/how-to-identify-when-an-attributes-attribute-is-being-set?noredirect=1&amp;lq=1">How to identify when an attribute&#39;s attribute is being set?</a></p>