110,546
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
namespace Command
{
public class Command_Sample01
{
public void Open()
{
Console.WriteLine("播放");
}
public void Close()
{
Console.WriteLine("暂停");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Command
{
public class TVcloseCommand:AbstractCommand
{
private Command_Sample01 tv;
public TVcloseCommand()
{
tv = new Command_Sample01();
}
public void Execute()
{
tv.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Command
{
public class TvOpenCommand:AbstractCommand
{
#region AbstractCommand 成员
private Command_Sample01 tv;
public TvOpenCommand()
{
tv = new Command_Sample01();
}
public void Execute()
{
tv.Open();
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Command
{
public interface AbstractCommand
{
void Execute();
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Command
{
public class Controller
{
private AbstractCommand openCommand, CloseCommand;
public Controller(AbstractCommand openCommand, AbstractCommand CloseCommand)
{
this.openCommand = openCommand;
this.CloseCommand = CloseCommand;
}
public void Open()
{
openCommand.Execute();
}
public void Close()
{
CloseCommand.Execute();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Reflection;
namespace Command
{
class Program
{
static void Main(string[] args)
{
AbstractCommand openCommand, CloseCommand;
string open = ConfigurationManager.AppSettings["TvOpenClass"];
openCommand = (AbstractCommand)Assembly.Load("Command").CreateInstance(open);
string Close = ConfigurationManager.AppSettings["TvCloseClass"];
CloseCommand = (AbstractCommand)Assembly.Load("Command").CreateInstance(Close);
//string Control = ConfigurationManager.AppSettings["Conntrol"];
//Controller control = (Controller)Assembly.Load("Command").CreateInstance(Control);
Controller control = new Controller(openCommand, CloseCommand);
control.Open();
control.Close();
Console.Read();
}
}
}