c# - I have created a class for executing actions, but which extendable design pattern should I actually use here? -


i have created class can execute methods string code (this want actually, since (already existing) database contains these codes. want more extendible add more database records. have create method each code, want use interface , class can created without editing class. guys have suggestions?

   public class specificaction     {     public actiontoperform actiontoperform { get; private set; }             public string action { { return actiontoperform.action.code; } }       public specificaction(actiontoperform actiontoperform)     {         actiontoperform = actiontoperform;     }      public dynamic execute(object[] parametersarray = null)     {         type type = typeof (specificaction);          methodinfo methodinfo = type.getmethod(action);          dynamic result = null;         if (methodinfo != null)         {             parameterinfo[] parameters = methodinfo.getparameters();             result = methodinfo.invoke(this, parameters.length == 0 ? null : parametersarray);         }         return result != null && result;     }      //"restart" 1 of codes in database     public bool restart()     {         throw new notimplementedexception();     }      //"addtoeventlog" 1 of codes in database     public bool addtoeventlog()     {         if (!eventlog.sourceexists("actions"))         {             eventlog.createeventsource("actions", "application");         }         eventlog.writeentry("actions", action + "is executed", eventlogentrytype.warning);         return true;     }      //"sendemail" 1 of codes in database     public bool sendemail()     {         throw new notimplementedexception();     } } 

i call , works:

        bool isperformed = false;          var action = new specificaction(actiontoperform);         isperformed = action.execute(); 

however, find way better implement class each possible action , dynamically execute method in there, possible of existing patterns, give me example, since have tried lot?

generally type of problem solved using command pattern.

the command pattern "encapsulates information required call method @ later date."

more on command pattern.

the command pattern employs abstract base class (or interface) command build inheritance hierarchy of commands. in way not need know command execute @ runtime, interface required invoke it.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -