With the hope of learning the Command pattern, I have set up a simple GUI application in C# with two buttons. The first button uses (my attempt at) the Command pattern to perform an operation, whereas the second simply calls a static method in another class.
Here is the form code
private void CommandButton_Click(object sender, EventArgs e)
{
ICommand command = new ConcreteCommand();
command.Execute(); //Performs the same code as DoOperation()
}
private void StaticButton_Click(object sender, EventArgs e)
{
Helper.DoOperation(); //Performs the same code as Execute()
}
My questions are:
Command Pattern is used to do set of operations based on the value in command argument, whereas in the code you have shown there is no dependency on the current state. In your case I static method would be fine.
But this wont always be the case so study well your need and then opt for the way to proceed, I would have gone for Command Pattern as this gives more flexibility with future change to requirement.