【发布时间】:2020-08-09 16:42:34
【问题描述】:
大家好。
我想做这样的事
public class CommandExecutor
{
public List<ICommand> _commandList = new List<ICommand>()
public void ExecuteCommands()
{
for(int i = 0; i < _commandList.Count; i++)
{
_commandList[i].Execute();
}
}
}
使用此设置:
public interface ICommand
{
void Execute();
}
public interface IDirectionalCommand : ICommand
{
}
public interface IImpulseCommand : ICommand
{
}
public class ExampleCommand1 : IImpulseCommand
{
public void Execute()
{
DoStuff();
}
}
public class ExampleCommand2 : IDirectionalCommand
{
public void Execute(Vector2 direction)
{
DoStuff(direction);
}
}
但我不明白这是怎么做到的。 PS:对不起,如果标题没有完全抓住这里的问题,我很难措辞这个问题。
【问题讨论】:
标签: c# inheritance interface