title: C# How to add auxiliary functionality to the class/delegating?
body: <p>This might turn out to be newbie question, as simple as not possible, but I will give it go anyway. I am coming from JavaScript background, so not sure if C# (and other OOP languages) have anything inbuilt to solve this problem.</p>
  
  <p>I want to add auxiliary functionality to my class using interfaces &amp; impleentation delegated to separate concrete classes so that they can be resused. </p>
  
  <p>In following implementation, I am using "LibraryClass" from external API which I cannot modify. I am writing "MyClass" which uses it by extending it.</p>
  
  <pre><code>public class LibraryClass {...}
  
  public class MyClass : LibraryClass {...}
  </code></pre>
  
  <p>Now I want to add functionlity such as paging. So what I did, I created new class "Paging" which extends "LibraryClass" &amp; extended "MyClass" from it.</p>
  
  <p><strong>Current Implementation</strong></p>
  
  <pre><code>public class LibraryClass {...}
  
  public class Paging : LibraryClass {
      protected int pageNumber = 1;
  
      public void setPaging(TRequest request) {
          var httpReq = this.RequestContext.Get&lt;IHttpRequest&gt;();
          pageNumber = httpReq.QueryString["page"]; // parsing syntax skipped
      }
  }
  public class MyClass : Paging {
      public override object OnGet(Products request) {
          setPaging(request);
          return new ProductsResponse { Products = GetAll() };
      }
  
      private List&lt;Product&gt; GetAll() {
          // Use base.pageNumber to pull appropriate data
      }
  }
  </code></pre>
  
  <p>Can this be more cleaner way with interfaces or any other C# mechanism?</p>
  
  <p><strong>Proposed Implementation</strong></p>
  
  <pre><code>public class LibraryClass {...}
  public interface IPaging : LibraryClass {
      void setPaging(TRequest request)
  }
  public interface Paging : IPaging {
      public void setPaging(TRequest request) {
          var httpReq = this.RequestContext.Get&lt;IHttpRequest&gt;();
          pageNumber = httpReq.QueryString["page"]; // parsing syntax skipped
      }        
  }
  public class MyClass : IPaging {...}
  </code></pre>
  
  <p>I also want to add more "concrete" functionality to MyClass like access &amp; delegate implementation to another class.</p>
  
  <pre><code>public interface IAuth {...}
  public class Auth : IAuth {...}
  public class MyClass : IPaging, IAuth {...}
  </code></pre>
  
  <p>The key here is separation of code.</p>
  
  <p>I might have missed some basic OOP class in school, but its never tool late I guess.</p>