title: Correct way to implement strategy design Pattern in C#
body: <p>I have a scenario wherein there are multiple conditions and I have to write a code in such a way that it should be open for extension and not for modification so I went with the strategy design pattern, below is my code, let me know if I'm on the correct path and need some guidance on the code written.</p>
  <pre class="lang-cs prettyprint-override"><code>// Is this correct way to call it, how to apply dependency injection?
  // You can find this code in the end
  BaseOrderProcessing baseOrderProcessing =
      new BaseOrderProcessing(
          new BaseSubscribe(
              new SubscribeService(
                  Subscribe)));  
  </code></pre>
  <p>Here is the actual code:</p>
  <pre class="lang-cs prettyprint-override"><code>public interface IBaseOrderProcessing
  {
      void ProcessOrder();
  }
  
  public class BaseOrderProcessing : IBaseOrderProcessing
  {
      private IBaseOrderProcessing _baseOrderProcessing = null;
      public BaseOrderProcessing(IBaseOrderProcessing baseOrderProcessing)
      {
          _baseOrderProcessing = baseOrderProcessing;
      }
      public virtual void ProcessOrder()
      {
          _baseOrderProcessing.ProcessOrder();
      }
  }
  
  public interface ISubscribeService
  {
      SubscribeType SubscribeType { get; set; }
      void ActivateSubscribe();
  
      void UpgradeSubscribe();
  }
  
  // Strategy Pattern 1  =&gt; Subscribe is one of the &quot;if&quot; condition
  public class BaseSubscribe : IBaseOrderProcessing
  {
      private ISubscribeService _SubscribeService = null;
      public BaseSubscribe(ISubscribeService SubscribeService)
      {
          _SubscribeService = SubscribeService;
      }
      
      public void ProcessOrder()
      {
          if (_SubscribeService.SubscribeType == SubscribeType.ACTIVATE)
              _SubscribeService.ActivateSubscription();
  
          if (_SubscribeService.SubscribeType == SubscribeType.UPGRADE)
              _SubscribeService.UpgradeSubscription();
          
      }
  }
  
  // Writing another class to simplify is correct ?????
  public class SubscribeService : ISubscribeService
  {
      private SubscribeDetails _Subscribedetails = null;
  
      public SubscribeType SubscribeType { get; set; }
  
      public SubscribeService(SubscribeDetails Subscribedetails)
      {
          _Subscribedetails = Subscribedetails;
          SubscribeType = Subscribedetails.SubscribeType;
      }
      public void ActivateSubscription()
      {
          // Code to save the Subscribe details in the database
          Console.WriteLine(
              $&quot;\n\nSubscribe {_Subscribedetails.SubscribeId} for &quot; +
              $&quot;{_Subscribedetails.SubscribeName} activated for order Id: {_Subscribedetails.OrderId}&quot; +
              $&quot; from {_Subscribedetails.SubscribeStartDate} to {_Subscribedetails.SubscribeEndDate}&quot;);        
      }      
  
      public void UpgradeSubscription()
      {
          // Code to upgrade the Subscribe details in the database
          Console.WriteLine(
              $&quot;\n\nSubscribe {_Subscribedetails.SubscribeId} for &quot; +
              $&quot;{_Subscribedetails.SubscribeName} upgraded for order Id: {_Subscribedetails.OrderId}&quot; +
              $&quot; from {_Subscribedetails.SubscribeStartDate} to {_Subscribedetails.SubscribeEndDate}&quot;);
  
      }
  }  
  </code></pre>
  <p>Client code:</p>
  <pre class="lang-cs prettyprint-override"><code>// Is this correct way to call it, how to apply dependency injection?
  IBaseOrderProcessing baseOrderProcessing = null;
  SubscribeDetails Subscribe = new SubscribeDetails();
  
  Subscribe.OrderId = Guid.NewGuid();
  Subscribe.SubscribeId = Guid.NewGuid();
  Subscribe.SubscribeName = &quot;Amazon&quot;;
  Subscribe.SubscribeStartDate = DateTime.Now;
  Subscribe.SubscribeEndDate = DateTime.Now.AddDays(30);
  if (option == 1)
      Subscribe.SubscribeType = SubscribeType.ACTIVATE;
  
  if (option == 2)
      Subscribe.SubscribeType = SubscribeType.UPGRADE;
  
  baseOrderProcessing =
      new BaseOrderProcessing(
          new BaseSubscribe(
              new SubscribeService(
                  Subscribe)));  
  </code></pre>