c# - Program Flow using Events -


i'm trying write program step 1 -> kick off step 2 -> kick off step 3. variables passed in between each step.

can use events way in c#? might best way write program this?

public class programflow // listener program {     eventargs args = null;     public delegate void eventhandler(string str, eventargs e);     public static event eventhandler step1reached;     public static event eventhandler step2reached;             public programflow()     {         step1 step1 = new step1();           // print string , kick off step2          step2 step2 =new step2();         // print string kick off next step      } }  public class step1 {     string charread;      public step1()     {         console.write("input step1: ");         charread = console.readline();         console.writeline();                     programflow.step1reached += programflow_step1reached;     }      void programflow_step2reached(string str, eventargs e)     {         console.writeline(charread);     }  }  public class step2 {     string charread;     public step2()     {         console.write("input step2: ");         charread = console.readline();         console.writeline();         programflow.step2reached += programflow_step2reached;     }      void programflow_step2reached(string str, eventargs e)     {         console.writeline(charread);     } } class program {     static void main(string[] args)     {         programflow programflow = new programflow();         console.readkey();                   } } 

would interfacing steps out , having program flow coordinate execution meet requirements e.g.

public class programflow // listener program {     public programflow()     {         istep[] steps = new istep[] { new step1(), new step2() };          foreach (var step in steps)         {             step.step();             step.stepresult();         }     } }  public interface istep {     void step();     void stepresult(); }  public class step1 : istep {     string stringread;      public void step()     {         console.write("input step1: ");         stringread = console.readline();         console.writeline();     }      public void stepresult()     {         console.writeline(stringread);     } }  public class step2 : istep {     string stringread;      public void step()     {         console.write("input step2: ");         stringread = console.readline();         console.writeline();     }      public void stepresult()     {         console.writeline(stringread);     } }  class program {     static void main(string[] args)     {         programflow programflow = new programflow();         console.readkey();     } } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -