title: How to avoid long switch ..need help refactoring
body: <p>i needed help refactoring the following class,</p>
  
  <p>Following is a class Operation with variety of Operations in switch : 
  i want to avoid the switch statement.I read few articles on using polymorphism and state   pattern .but when i refactor the classes i dont get access to many variables,properties<br>
  Im confused on whether to use operation as abstract class or to implement an interface.<br>
  Just wanted to know which type of refactoring will help in this case<br>
  polymorphism or state pattern?<br>
  And when to use them?    </p>
  
  <pre><code>public class Operation
      {
          public enum OperationType
          {
              add,
              update,
              delete,
              retrieve
          }
          public enum OperationStatus
          {
              Success,
              NotStarted,
              Error,
              Fail,
              InProcess,
              Free
          }
  
      // raise this event when operation completes
      public delegate void OperationNotifier(Operation operation);
      public event OperationNotifier OperationEvent=null;           
  
      private OperationStatus _status=OperationStatus.Free;
      public OperationStatus Status
      {
          get { return _status; }
          set { _status = value; }
      }      
  
  
      private string _fileName = null;
  
      public string FileName
      {
          get { return _fileName; }
          set { _fileName = value; }
      }
  
      private string _opnid = null;
  
      public string OperationId
      {
          get { return _opnid; }
          set { _opnid = value; }
      }
  
      private OperationType _type;
      public OperationType Type
      {
          get { return _type; }
          set { _type = value; }
      }
  
     public void performOperation(OperationType type, string parameters)
      {  
  
          switch (type)
          {
              case OperationType.add:
                  _status = addOperation(parameters);                   
                  break;
              case OperationType.update:
                 _status = updateOperation(parameters);
                  break;
              case OperationType.delete:
                  _status = deleteOperation(parameters);
                  break;
              case OperationType.retrieve:
                  _status = retrieveOperation(parameters);
                  break;
              default:
                  break;
          }
          if (OperationEvent != null)
              OperationEvent(this);           
         // return true;
      }
  
  
      public OperationStatus addOperation(string parameters)
      {           
          DateTime start = DateTime.Now;
           //Do SOMETHING BIG
          TimeSpan timeTaken = DateTime.Now - start;
          System.Diagnostics.Debug.WriteLine("addOperation:-" + _opnid + "-" + _fileName + "--" + timeTaken.Milliseconds); 
          return OperationStatus.Success;
  
          }
  ...other operations here....
  </code></pre>
  
  <p>Calling code is similar to :</p>
  
  <pre><code>  Operation oprnObj;
                  Operation.OperationType operationType;
  
   oprnObj = new Operation();
   oprnObj.FileName = String.Concat("myxmlfile",".xml");
   oprnObj.OperationId = oprnid;
   oprnObj.OperationEvent += new Operation.OperationNotifier(oprnObj_OperationEvent);
   operation="add"; //get From Outside function getOperation()
   operationType = (Operation.OperationType)Enum.Parse(typeof(Operation.OperationType),   operation.ToLower(), true);
   oprnObj.Type = operationType;
   oprnObj.performOperation(operationType, parameters);
  </code></pre>
  
  <p>References Threads:<br>
  <a href="https://stackoverflow.com/questions/126409/ways-to-eliminate-switch-in-code">Link</a><br>
  <a href="https://stackoverflow.com/questions/942481/refactoring-advice-for-big-switches-in-c">Link</a><br>
  ..many more.</p>