How to avoid circular dependencies when setting Properties? <p>This is a design principle question for classes dealing with mathematical/physical equations where the user is allowed to set any parameter upon which the remaining are being calculated. In this example I would like to be able to let the frequency be set as well while avoiding circular dependencies.</p> <p>For example:</p> <pre><code>from traits.api import HasTraits, Float, Property from scipy.constants import c, h class Photon(HasTraits): wavelength = Float # would like to do Property, but that would be circular? frequency = Property(depends_on = 'wavelength') energy = Property(depends_on = ['wavelength, frequency']) def _get_frequency(self): return c/self.wavelength def _get_energy(self): return h*self.frequency </code></pre> <p>I'm also aware of an update trigger timing problem here, because I don't know the sequence the updates will be triggered:</p> <ol> <li>Wavelength is being changed</li> <li>That triggers an updated of both dependent entities: frequency and energy</li> <li>But energy needs frequency to be updated so that energy has the value fitting to the new wavelength!</li> </ol> <p>(The answer to be accepted should also address this potential timing problem.)</p> <p>So, what' the best design pattern to get around these inter-dependent problems? At the end I want the user to be able to update either wavelength or frequency and frequency/wavelength and energy shall be updated accordingly.</p> <p>This kind of problems of course do arise in basically all classes that try to deal with equations.</p> <p>Let the competition begin! ;)</p>