Building a basic Command structure
The first piece of any Command pattern structure is the common interface all our commands need to implement. This can be an interface or abstract class, but I’m going to use abstract classes so we can add default logic later. The base abstract class for all commands is simple – they all need an Execute method. We’ll start with building out commands that can be reused (i.e., don’t have a reference to a specific receiver when concrete subclasses are instantiated), and then move on to coupled commands with internal state information.
Creating reusable commands
In the Scripts folder, create a new C# script named ReusableCommand, and update its code to match the following code. All we’ve done here is declared ReusableCommand as abstract to make sure we’re forced to create concrete commands and added an abstract Execute method that doesn’t return anything. This is the basis for how we encapsulate...