I want to know which of these two FiniteStateMachine.AddState()
methods is better than the other, for example, does one require unboxing/boxing? or do both require unboxing/boxing? and if any of them is better than the other, which one?
public interface IState
{
string Name { get; set; }
}
public sealed class FiniteStateMachine
{
private Dictionary<string, IState> allStates = new Dictionary<string, IState>();
public void AddState<TState>(TState newState) where TState : IState
{
allStates.Add(newState.Name, newState);
}
public void AddState(IState newState)
{
allStates.Add(newState.Name, newState);
}
}
public class EnemySoldierSword_TakingHitState : IState
{
public string Name { get; set; }
public EnemySoldierSword_TakingHitState(string name)
{
Name = name;
}
}
public class Program
{
public var FSM = new FiniteStateMachine();
FSM.AddState(new EnemySoldierSword_ChasingState("ChasingState"));
}