Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Then you should raise twice, in Length and Width property setters. One for the actual property and one for the Area property.</p> <p>for example:</p> <pre><code>private int _width; public int Width { get { return _width; } set { if (_width == value) return; _width = value; NotifyPropertyChanged("Width"); NotifyPropertyChanged("Area"); } } </code></pre> <blockquote> <p>People here suggested that Length and Width also call NotifyPropertyChanged for Area. Again, I think this is an anti-pattern. A property (IMHO) shouldn't be aware of who depends on it, as shouldn't NotifyPropertyChanged. Only the property should be aware of who it depends on.</p> </blockquote> <p>This is not an anti-pattern. Actually, your data encapsulated inside this class, so this class knows when and what changed. You shouldn't know outside of this class that Area depends on Width and Length. So the most logical place to notify listeners about Area is the Width and Length setter.</p> <blockquote> <p>A property (IMHO) shouldn't be aware of who depends on it, as shouldn't NotifyPropertyChanged.</p> </blockquote> <p>It does not break encapsulation, because you are in the same class, in the same data structure. </p> <p><strong>An extra information</strong> is that knockout.js (a javascript mvvm library) has a concept which accessing this problem: <a href="http://knockoutjs.com/documentation/computedObservables.html" rel="nofollow">Computed Observables</a>. So I believe this is absolutely acceptable.</p>
 

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