Note that there are some explanatory texts on larger screens.

plurals
  1. POHow best to handle interdependent properties?
    primarykey
    data
    text
    <p>Perhaps properties aren't the way to go with this, but I'm struggling to find an answer as for a good solution.</p> <pre class="lang-cs prettyprint-override"><code>public class Blah { public double A { get{ return _B / _C; } } public double B { get{ return _A * _C; } set{ _B = value; } } public double C { get{ return _B / _A; } set{ _C = value; } } private double _A; private double _B; private double _C; public Blah(){} public Blah(double a, double b, double c) { this._A = a; this._B = b; this._C = c; } } </code></pre> <p>Assuming A is always a read-only property, what's a good way to go about handling an arbitrary amount of additional properties that may affect the output of A? I feel this is a bad (completely wrong!) way to do this because I should always be able to retrieve a value I assign. For example, if I assign B = 3, then I should be able to get 3 the next time I call B instead of getting _A * _C.</p> <p>However, I need for this type of interdependence to exist (or a completely different approach that achieves the same goal). All of the values are related, so I need for the change of one value to be reflected in the others.</p> <p>I just can't figure out the appropriate way to do this.</p> <p><strong>Edit</strong></p> <p>I made a bad example. In reality, the non-A values aren't dependent on A, but only each other -- B affects C, C affects D, etc; however, A is just some combination of those values. Not sure if that matters as for how to best approach this, but thought it was worth mentioning.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload