title: How to correctly implement State Pattern?
body: <ol>
  <li>An Account could have various states such as Frozen, Active, NotVerified, Closed. </li>
  <li>And Account could perform following actions: Deposit(), Withdraw(), HolderVerified(), Close(), Freeze()</li>
  <li>These implementation of these actions could vary depending on current state of the account. </li>
  </ol>
  
  <p>Below is my way of tackling the above scenario. 
  However, what if we have a situation where we have to :</p>
  
  <p><strong>Deduct 10 percent of the deposit when the deposit is made when current state of the account is Frozen?</strong></p>
  
  <p><strong>ACCOUNT</strong></p>
  
  <pre><code>    class Account
      {
          public decimal Balance { get; private set; }
  
          private IAccountState State { get; set; }
  
          public Account(Action onUnfreeze)
          {
              this.State = new NotVerified(onUnfreeze);
          }
  
          public void Deposit(decimal amount)
          {
              this.State = this.State.Deposit(() =&gt; { this.Balance += amount; });
          }
  
          public void Withdraw(decimal amount)
          {
              this.State = this.State.Withdraw(() =&gt; { this.Balance -= amount; });
          }
  
          public void HolderVerified()
          {
              this.State = this.State.HolderVerified();
          }
  
          public void Close()
          {
              this.State = this.State.Close();
          }
  
          public void Freeze()
          {
              this.State = this.State.Freeze();
          }
      }
  </code></pre>
  
  <p><strong>IAccountState</strong></p>
  
  <pre><code>interface IAccountState
      {
          IAccountState Deposit(Action addToBalance);
          IAccountState Withdraw(Action substractFromBalance);
          IAccountState Freeze();
          IAccountState HolderVerified();
          IAccountState Close();
  
      }
  </code></pre>
  
  <p><strong>Concrete Implementation of IAccountState</strong></p>
  
  <p><strong>ACTIVE</strong></p>
  
  <pre><code>class Active : IAccountState
      {
          private Action OnUnfreeze { get; }
          public Active(Action onUnfreeze)
          {
              OnUnfreeze = onUnfreeze;
          }
  
  
  
          public IAccountState Deposit(Action addToBalance)
          {
              addToBalance();
              return this;
          }
  
      public IAccountState Withdraw(Action substractFromBalance)
      {
          substractFromBalance();
          return this;
      }
  
      public IAccountState HolderVerified() =&gt; this;
      public IAccountState Freeze() =&gt; new Frozen(this.OnUnfreeze);
      public IAccountState Close() =&gt; new Closed();
  }
  </code></pre>
  
  <p><strong>NOTVERIFIED</strong></p>
  
  <pre><code>class NotVerified : IAccountState
      {
          public Action OnUnfreeze { get; }
          public NotVerified(Action onUnfreeze)
          {
              this.OnUnfreeze = onUnfreeze;
          }
          public IAccountState Close() =&gt; new Closed();
  
          public IAccountState Deposit(Action addToBalance)
          {
              addToBalance();
              return this;
          }
  
          public IAccountState Freeze() =&gt; this;
  
          public IAccountState HolderVerified() =&gt; new Active(this.OnUnfreeze);
  
          public IAccountState Withdraw(Action substractFromBalance) =&gt; this;
      }
  </code></pre>
  
  <p><strong>How will you deal with the situation when you have to deduct 10 percent of the deposit  when current state of the account is Frozen?</strong></p>
  
  <p>I am not sure how to modify Deposit method in NotVerified class to meet the requirement :</p>
  
  <pre><code> public IAccountState Deposit(Action addToBalance)
   {
      addToBalance();
      return this;
   }
  </code></pre>