title: Workaround for Multiple Inheritance in C#
body: <p>I have to implement classes to transfer files to USB (<code>class USBTransfer</code>) and over FTP (<code>class FTPTransfer</code>). Since both the classes use some common methods (like getting the filename, reading some parameters etc.) so, I have implemented those methods in an another class (<code>class FileOperations</code>). I have inherited both the classes (i.e. <code>class USBTransfer</code> and <code>class FTPTransfer</code>) from the <code>class FileOperations</code>.</p>
  
  <pre><code>class FileOperations
  {
      protected void CommonMethod1();
      protected void CommonMethod2();
  }
  
  class USBTransfer : FileOperations
  { 
  
  }
  
  class FTPTransfer : FileOperations
  {
  
  }
  </code></pre>
  
  <p><strong>PROBLEM:</strong> During the file transfer operations, I set different states (not using the state machine design pattern though). I want to use a <strong>ABSTRACT</strong> class for this purpose with the following structure.</p>
  
  <pre><code>abstract class FileTransferStateMachine
  {
      //Public
      public enum FileTransferStates { Idle = 0, FileCopyingState = 1, SuccessfullyCopiedState = 2 }
      public static FileTransferStates CurrentState = FileTransferStates.Idle;
  
      abstract protected void IdleState();
      abstract protected void FileCopyingState();
      abstract protected void SuccessfullyCopiedState();
  }
  </code></pre>
  
  <p>But in C# it is not allowed to have multiple inheritance. </p>
  
  <p><strong>QUESTION:</strong> I know that I can use interface. But you cannot have variables and in that case both of my classes (i.e. <code>class USBTransfer</code> and <code>class FTPTransfer</code>) will have their own variables for the following </p>
  
  <pre><code>public enum FileTransferStates { Idle = 0, FileCopyingState = 1, SuccessfullyCopiedState = 2 }
  public static FileTransferStates CurrentState = FileTransferStates.Idle;
  </code></pre>
  
  <p>I want to reduce redundancy and want to force to have same variables/methods (hmm...same methods can be achieved by interface) for the state machine.</p>
  
  <p><strong>Question PART-2:</strong> I can transfer files to USB or FTP as mentioned above but both the transfer operations have some common states like <code>IdleState</code>, <code>FileCopyingState</code> or <code>SuccessfullyCopiedState</code> which have their corresponding methods (i.e. <code>IdleState()</code>, <code>FileCopyingState()</code> or <code>SuccessfullyCopiedState()</code>). I want to <strong>FORCE</strong> both the classes to implement these methods (i.e. <code>IdleState()</code>, <code>FileCopyingState()</code> or <code>SuccessfullyCopiedState()</code>). If any class forgets to implement any method then, I should get a compiler error. Basically, the <code>FileTransferStateMachine</code> should be an interface/abstract class whose methods should be overridden in <code>USBTransfer</code> and <code>FTPTransfer</code> classes (which are already inheriting another class called <code>FileOperations</code>).</p>