title: Open/Close Principle in OOPS
body: <p>I am working on a telecom project. I have implemented Open/Closed principle in my project. Below are my classes.</p>
  
  <p>MainServiceClass.CS</p>
  
  <pre><code>public abstract class BaseServiceClass
  {
      public abstract IEnumerable&lt;string&gt; GetServiceData();
      public abstract IEnumerable&lt;string&gt; GetDashBoardData();
  }
  </code></pre>
  
  <p>Web_Service.CS</p>
  
  <pre><code>public class WebServiceClass : BaseServiceClass
  {
      public override IEnumerable&lt;string&gt; GetServiceData()
      {
          List&lt;string&gt; MyList = new List&lt;string&gt;();
          return MyList;
      }
  
      public override IEnumerable&lt;string&gt; GetDashBoardData()
      {
          List&lt;string&gt; MyList = new List&lt;string&gt;();
          return MyList;
      }
  }
  </code></pre>
  
  <p>Voice_Service.CS</p>
  
  <pre><code>public class VoiceSericeClass : BaseServiceClass
  {
      public override IEnumerable&lt;string&gt; GetServiceData()
      {
          List&lt;string&gt; MyList = new List&lt;string&gt;();
          return MyList;
      }
  
      public override IEnumerable&lt;string&gt; GetDashBoardData()
      {
          List&lt;string&gt; MyList = new List&lt;string&gt;();
          return MyList;
      }
  }
  </code></pre>
  
  <p>In the future, If I need to implement Video service, I will create a new Video_Service class.I believe that I will achieve Open/Close principle.</p>
  
  <p>If I need to add a new method in my MainServiceClass.cs , I will add a new Method (<strong>GetNewTypeOfData()</strong>). </p>
  
  <p>Question : Here, I am modifying a class. Still, am I following OCP? Or, is there any way to add new method in the MainServiceClass.cs??</p>
  
  <p>Please suggest.</p>
  
  <p><strong>P.S. I need to implement this method in all the derived classes i.e. Web_Service.cs, Voice_Service.cs, and Video_Service.cs</strong></p>
  
  <blockquote>
    <p>Updating my question after CrudaLilium reply.</p>
  </blockquote>
  
  <p>This is my understanding. Please correct me if I am wrong.</p>
  
  <p>My Current Code :</p>
  
  <pre><code> public interface IMainBase
  {
      IEnumerable&lt;string&gt; GetData2016();
  }
  
  public class VoiceService : IMainBase
  {
      public IEnumerable&lt;string&gt; GetData2016()
      {
          return Enumerable.Empty&lt;string&gt;();
      }
  }
  </code></pre>
  
  <p>I would get a new requirement in 2017. So, I will update my code in 2017</p>
  
  <pre><code>public interface IMainBase
  {
      IEnumerable&lt;string&gt; GetData2016();
  }    
  
  public class VoiceService : IMainBase
  {
      public IEnumerable&lt;string&gt; GetData2016()
      { 
          return Enumerable.Empty&lt;string&gt;();
      }
  }
  
  //New Code will be Added in 2017....Start
  
  public interface IMainBase2017 : IMainBase
  {
      IEnumerable&lt;string&gt; GetData2017();
  }
  
  public class voiceService2017 : VoiceService, IMainBase2017
  {
      public IEnumerable&lt;string&gt; GetData2017()
      {
          return Enumerable.Empty&lt;string&gt;();
      }
  }
  
  //New Code Added be in 2017...Ended
  </code></pre>
  
  <p>I would again get a new requirement in 2018. So, I will update my code in 2018.</p>
  
  <pre><code> public interface IMainBase
  {
      IEnumerable&lt;string&gt; GetData2016();
  }    
  
  public class VoiceService : IMainBase
  {
      public IEnumerable&lt;string&gt; GetData2016()
      { 
          return Enumerable.Empty&lt;string&gt;();
      }
  }
  
  //New Code will be Added in 2017....Start
  
  public interface IMainBase2017 : IMainBase
  {
      IEnumerable&lt;string&gt; GetData2017();
  }
  
  public class voiceService2017 : VoiceService, IMainBase2017
  {
      public IEnumerable&lt;string&gt; GetData2017()
      {
          return Enumerable.Empty&lt;string&gt;();
      }
  }
  
  //New Code Added be in 2017...Ended
  
  //New Code will be Added in 2018...Start
  
  public class WebService2018 : IMainBase2017
  {
      public IEnumerable&lt;string&gt; GetData2016()
      {
          return Enumerable.Empty&lt;string&gt;();
      }
  
      public IEnumerable&lt;string&gt; GetData2017()
      {
          return Enumerable.Empty&lt;string&gt;();
      }
  }
  
  
  //New Code will be Added in 2018...End
  </code></pre>
  
  <p>As per above code, I am not violating OCP. Is this a good practice or do I have any alternative way also?</p>