title: When to check the state of an object, general OOP, example in C#
body: <p>I'm not quite sure how to word this question in a sentence so I had difficulty searching previous posts.  This comes up frequently for me and I'd like to get consensus on how to approach it.</p>
  
  <p>Say you have two classes, <code>ExampleClass</code> and <code>ExampleClassManager</code>. <code>ExampleClass</code> has an <code>Update(Data data)</code> method which is called from <code>ExampleClassManager</code>. However, <code>ExampleClass</code> can be in one of two states, and in the <code>Enabled</code> state it wants to process the <code>data</code> passed to it in <code>Update</code>, and in the <em>disabled</em> state it doesn't do anything with the <code>data</code> at all. </p>
  
  <p>Should I be checking for the state in the <code>ExampleClassManager</code> and not passing the <code>data</code> at all if it is <em>disabled</em>, or should I pass the <code>data</code> regardless and ignore it within <code>ExampleClass</code>? </p>
  
  <p>Here's a code example in case I didn't articulate it clearly. </p>
  
  <pre><code>public class ExampleClass {
      public bool Enabled {
          get;
          set;
      }
  
      public void Update(Data data) {
          if(Enabled) {
              //do stuff with data
          }
      }
  }
  
  public class ExampleClassManager {
      private List&lt;ExampleClass&gt; exampleClassList=new List&lt;ExampleClass&gt;();
  
      public void UpdateList() {
          foreach(ExampleClass exampleClass in exampleClassList) {
              exampleClass.Update(data);
          }
      }
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>public class ExampleClass {
      public bool Enabled {
          get;
          set;
      }
  
      public void Update(Data data) {
          //do stuff with data
      }
  }
  
  public class ExampleClassManager {
      private List&lt;ExampleClass&gt; exampleClassList=new List&lt;ExampleClass&gt;();
  
      public void UpdateList() {
          foreach(ExampleClass exampleClass in exampleClassList) {
              if(exampleClass.Enabled) {
                  exampleClass.Update(data);
              }
          }
      }
  }
  </code></pre>