The command object template is one that I still could not really understand, and I found an implementation in the code that I am currently working in, so I studied it for a long time, and it was difficult for me to understand if I can finally get it real world example. The problem is that I'm sure this is not implemented correctly, and this is just an attempt by someone who just read about it and thought it made sense here.
Let me show you this (for privacy reasons this will be greatly simplified, but I will do my best to show the basic concepts):
public class CommandOne
{
public CommandOne(Manager manager, MyForm form)
{
m_manager = manager;
m_form = form;
}
public void Execute()
{
m_manager.CommandOne(m_form);
}
}
public class CommandTwo
{
public CommandTwo(Manager manager, MyForm form)
{
m_manager = manager;
m_form = form;
}
public void Execute()
{
m_manager.CommandTwo(m_form);
}
}
The first thing that strikes me as strange is that these two classes do not inherit from any abstract class and do not implement a common interface.
, , :
public class MyForm : System.Windows.Forms.Form
{
public MyForm(Manager manager)
{
m_manager = manager;
}
private void SomeMethod()
{
....
var cmd = new CommandOne(manager, this);
cmd.Execute();
...
}
private void OtherMethod()
{
....
var cmd = new CommandTwo(manager, this);
cmd.Execute();
...
}
}
, , , , . , "", , , , .
- , , , , , , , , ?
.