The implementation will be done in two parts. In the first part, we will code the core components of the Command pattern and then we will integrate the elements that are necessary to test the replay system:
- To start, we are implementing a base abstract class named Command, which has a singular method named Execute():
public abstract class Command
{
public abstract void Execute();
}
- Now we are going to write three concrete command classes that will derive from the Command base class, and then we will implement the Execute() method. Each of them encapsulates an action to execute.
The first one toggles the turbocharger on BikeController:
namespace Chapter.Command
{
public class ToggleTurbo : Command
{
private BikeController _controller;
public ToggleTurbo(BikeController controller)
{
_controller = controller;
}
public override void Execute()
{
_controller.ToggleTurbo();
...