public abstract class State
{
public virtual Enter(/* THIS NEED A PARAMETER */)
{
// an empty method
}
}
public class PlayerState : State
{
public override Enter(Player pl)
{
// method implementation
}
}
public class GoalkeeperState : State
{
public override Enter(Goalkeeper gk)
{
// method implementation
}
}
//EXAMPLE OF USE
public State globalState;
globalState.Enter(owner);
// OWNER CAN BE PLAYER OR GOALKEEPER
我知道虚拟方法和覆盖方法需要具有相同的“打印”。所以这里有一个设计缺陷。这样的事情也是可能的。我怎样才能做到这一点 ?你会怎么做?