static void Main(string[] args) { Document document = new Document(); ICommand displayCmd = new DisplayCommand(document); ICommand redoCmd = new RedoCommand(document); ICommand undoCmd = new UndoCommand(document); Invoker invoker = new Invoker(displayCmd, redoCmd, undoCmd); invoker.Display(); invoker.Redo(); invoker.Undo(); }
static void Main(string[] args) { TV sonyTV = new SonyTVFactory().Create(); TVCommand disCmd = new DisplayCommand(sonyTV); TVCommand moveNextCmd = new MoveNextCommand(sonyTV); TVCommand movePreCmd = new MovePreviousCommand(sonyTV); TV philipsTv = new PhilipsTVFactory().Create(); TVCommand movePreCmd_philips = new MovePreviousCommand(philipsTv); RemoteController rc = new RemoteController(disCmd, moveNextCmd, movePreCmd_philips); rc.Display(); rc.MoveNextChannel(); rc.MovePreviousChannel(); }
static void Main(string[] args) { //1、命令行模式的根本目的在于将“行为的请求者”和“行为的实现者”解耦;实现手段:“将行为抽象为对象” Document doc = new Document(); DocumentCommand discmd = new DisplayCommand(doc); DocumentCommand undcmd = new UndoCommand(doc); DocumentCommand redcmd = new RedoCommand(doc); DocumentInvoker invoker = new DocumentInvoker(discmd, undcmd, redcmd); invoker.Display(); invoker.Undo(); invoker.Redo(); PatrickLiuAndWife liuAndLai = new PatrickLiuAndWife(); //命令接受者 Command command = new MakeDumplingsCommand(liuAndLai); //命令 PaPaInvoker papa = new PaPaInvoker(command); //命令请求者 papa.ExecuteCommand(); Console.ReadKey(); }