I have this ICommand interface.
public interface ICommand
{
public void PerformUnitCommand(ICommandParameters params,UnityAction callback);
}
I want to extend classes with methods as such, with varying parameters so I tried to implement it like the following:
public class MoveToDestination : ICommand
{
public void PerformUnitCommand(ICommandParameters params, UnityAction callback) { ... }
}
public class Attack : ICommand
{
public void PerformUnitCommand(ICommandParameters params, UnityAction callback) { ... }
}
public class Harvest : ICommand
{
public void PerformUnitCommand(ICommandParameters params, UnityAction callback) { ... }
}
public class ICommandParameters
{
public Vector3 Destination;
public Target target;
public Resource targetResource;
}
What is the best practice on solving this problem? I feel like this is not what an interface is created for and I should be using a different pattern. But I also feel like my problem should be solve by the likes of interface where in my AI script I will only call PerformUnitCommand()
and the AI script will not have to know about the objects inside each class. Any thoughts is greatly appreciated !