mardi 29 mars 2022

what design pattern should i use to let the user decide the order that methods will be performed by

I have a class in which the Start() method calls many different methods in certain order. Each method can be called multiple times. There is a need to change this class in such way that in run-time the order of the methods will be defined and then the Start() method will run the methods in the defined order. What would be the best design pattern to use to achive this goal in c# ?

pseudo code example of the current implementation which i wish to change:

class Executer
{
   public Executer() { InitializeOrderOfMethodsBasedOnUserInput(); }

   public void Start()
   {
      /* some code here */
      
      PerformA();
      PerformC("C", 0);
      PerformA();
      PerformB(1);
      PerformB(9);
      PerformD();
   }

   private void PerformA() {}
   private void PerformB(int b) {}
   private bool PerformC(string c, int x) {}
   private void PerformD() {}
}

Aucun commentaire:

Enregistrer un commentaire