Dependent boolean properties
<p>Lets say I have an object with two boolean properties:</p>

<pre><code>public bool AdvancedMode{ get; set; }
public bool DumpDiagnostics{ get; set; }
</code></pre>

<p>The domain rules state that DumpDiagnostics is not allowed unless AdvancedMode is also true. So throughout the code you might see statements like this:</p>

<pre><code>if( options.AdvancedMode &amp;&amp; options.DumpDiagnostics ){ ... }
</code></pre>

<p>The problem with this is that it's easy to forget to add the check forAdvancedMode and accidentally check only for DumpDiagnostics. </p>

<pre><code>if( options.DumpDiagnostics ) // Oh no!
</code></pre>

<p>So there are two solutions that I can think of:</p>

<h3>Option 1: DumpDiagnostics only returns true when AdvancedMode is true.</h3>

<pre><code>public bool DumpDiagnostics
{ 
    get{ return AdvancedMode &amp;&amp; _dumpDiagnostics; }
    set{ _dumpDiagnostics = value; }
}
</code></pre>

<h3>Option 2: New property that reflects the condition I'm looking for</h3>

<pre><code>public bool CanDumpDiagnostics{ get{ return AdvancedMode &amp;&amp; DumpDiagnostics; } }
</code></pre>

<h3>Question: Which is better?</h3>

<p>Option #1 seems pretty easy and less prone to error. There's always one authority on whether diagnostics can be dumped. But, it does change the set -> get semantics where you can assign DumpDiagnostics = true, followed by if( DumpDiagnostics ) where it returns false. </p>

<p>Option #2 is good because it isolates the logic and makes it clear what the purpose is. The biggest drawback I see with it is that it's still easy to just check for DumpDiagnostics instead of using the new CanDumpDiagnostics property.</p>

<p>p.s. I know it's an awkward title but couldn't come up with something more precise, feel free to modify. </p>
