Beispiel #1
0
        static void Main(string[] args)
        {
            Document    document     = new Document();
            ICommand    openCommand  = new OpenCommand(document);
            ICommand    saveCommand  = new SaveCommand(document);
            ICommand    closeCommand = new CloseCommand(document);
            MenuOptions menu         = new MenuOptions(openCommand, saveCommand, closeCommand);

            menu.clickOpen();
            menu.clickSave();
            menu.clickClose();
            Console.ReadKey();
        }
Beispiel #2
0
        //命令模式 一个对象维护一个命令,一个命令维护一个具体功能,对象可触发命令来执行具体功能
        static void Main(string[] args)
        {
            NormalButton button       = new NormalButton();
            OpenCommand  openCommand  = new OpenCommand();
            CloseCommand closeCommand = new CloseCommand();

            button.Command = openCommand;
            button.ButtonClick();
            Console.WriteLine();
            button.Command = closeCommand;
            button.ButtonClick();
            Console.WriteLine();

            string  command     = ConfigurationManager.AppSettings["Command"];
            Command realcommand = (Command)Assembly.Load("Command").CreateInstance(command);

            button.Command = realcommand;
            button.ButtonClick();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Document    document  = new Document("doc1");
            Document    document2 = new Document("doc2");
            Application app       = new Application();

            app.Add(document);
            app.Add(document2);

            Command com = new OpenCommand(app);

            com.Execute();

            Command com2 = new PasteCommand(document2);

            com2.Execute();

            MacroCommand coms = new MacroCommand();

            coms.Add(com);
            coms.Add(com2);
            coms.Execute();
        }