title: Open Closed Principle C#: Is Private Set + Constructor Init an Example of it?
body: <p>My Workmate believes that the following code is an example of the Open Closed Principle in C#:</p>
  
  <pre><code>public class MyClass
  {
     public int Id { get; private set; }
  
     public int Count{ get; private set; }
  
     public int Maximum{ get; private set; }
  
     public MyClass(int id, int count, int maximum)
     {
         Id = id;
         Count = count;
         Maximum = maximum;
     }
  
     public PrintValueWithText()
     {
        Conlose.Writeline($"The value of the Id property is: {Id.ToString()}");
     }
  }
  </code></pre>
  
  <p>The reason that he gives is that: "The Id property's value is closed for modification once the class is constructed".</p>
  
  <p>I believe this is an incorrect interpretation. </p>
  
  <p>It is my understanding that the open closed principle has nothing to do with the value of a property being closed for modification.</p>
  
  <p>I believe that the Open Closed principle only relates to designing the class so that extending the <strong>behavior</strong> of the class is possible without modifying the existing code.</p>
  
  <p>i.e. if i was to go in and edit the <code>PrintIdWithText</code> method to also print the value of <code>Count</code> on a new line I would be violating the principle. Because I'm modifying the existing class. </p>
  
  <p>In order to satisfy the principle, I must design the class so that its extendable so that I can for example, inject in the print functionality by composition.</p>
  
  <p>Which would allow me to a later date, add functionality to print the print the value of <code>Maximum</code> on a new line.</p>
  
  <p>Is my interpretation of the principle correct?</p>
  
  <p>Is his interpretation incorrect?</p>