mardi 2 juin 2015

Implementing a Command Design Pattern with static methods C#

I know how to implement a Command Design pattern as follows:

public abstract class Command
{
   public abstract void Execute(string connectionString);
}

Say I inherit this ,as an example:

public class ConnectionCommand : Command
{
   public override void Execute(string ConnectionString)
   {
      ...do some stuff here...;
   }
}

Problem is to use this ConnectionCommand I need to first instantiate an object, but the commands are context free, so I would prefer to not have to instantiate anything to run the ConnectionCommand's Execute method. (P.S. the ConnectionCommand.Execute() will be run from an event ,in a delegate).

How would I recreate this kind of design pattern but allowing the methods to be statically called?

Aucun commentaire:

Enregistrer un commentaire