风动破

导航

设计模式之Command

public interface ICommand
{
bool Execute(string command);
}
public class Producer{
static List<ICommand> commands = new List<ICommand>();
public static List<ICommand> produceRequests()
{
if (commands.Count > 0) return commands;
commands.Add(new SkillManager());
return commands;
}
}

public class TcpClient
{
public static object obj = new object();
/// <summary>
/// 客í户§端?命ü令?处鋦理え?
/// </summary>
public void Accept(string command)
{
lock(obj){
List<ICommand> comm = Producer.produceRequests();
for(int i = 0;i<comm.Count;i++){
try{
if(comm[i].Execute(command)) return;
}
catch(Exception e)
{
Console.Write(e);
continue;
}
}
}
}
}
public class SkillManager : ICommand{
public bool Execute(string command){

}
}

posted on 2015-04-22 14:48  风动破  阅读(93)  评论(0)    收藏  举报