Patterns in SOME – Command
来源:互联网 发布:武汉java培训机构名单 编辑:程序博客网 时间:2024/05/02 04:53
Code in C#:
namespace Command_DesignPattern
{
using System;
abstract class Command
{
abstract public void Execute();
protected Receiver r;
public Receiver R
{
set
{
r = value;
}
}
}
class ConcreteCommand : Command
{
override public void Execute()
{
Console.WriteLine("Command executed");
r.InformAboutCommand();
}
}
class Receiver
{
public void InformAboutCommand()
{
Console.WriteLine("Receiver informed about command");
}
}
class Invoker
{
private Command command;
public void StoreCommand(Command c)
{
command = c;
}
public void ExecuteCommand()
{
command.Execute();
}
}
///<summary>
/// Summary description for Client.
///</summary>
public class Client
{
public static int Main(string[] args)
{
// Set up everything
Command c = new ConcreteCommand();
Receiver r = new Receiver();
c.R = r;
Invoker i = new Invoker();
i.StoreCommand(c);
// now let application run
// the invoker is how the command is exposed for the end-user
// (or a client) initiates the command,
// (e.g. toolbar button, menu item)
i.ExecuteCommand();
return 0;
}
}
}
Code in SOME:
CReceiver
InformAboutCommand()
ACommand ->CReceiver[w_R] //write-only property
a_Execute()
CConcreteCommand : ACommand
o_Execute()
CInvoker ->ACommand[w_Command]
ExecuteCommand()
CClient
main
CClient.main
{
// Set up everything
ACommand command<CConcreteCommand>.();
CReceiver receiver.();
command.R = receiver;
CInvoker invoker.();
invoker.Command = command;
// now let application run
// the invoker is how the command is exposed for the end-user
// (or a client) initiates the command,
// (e.g. toolbar button, menu item)
invoker.ExecuteCommand()
{
_command.Execute<CConcreteCommand>()
{
<% Console.WriteLine("Command executed"); %>
_r.InformAboutCommand()
{
<% Console.WriteLine("Receiver informed about command"); %>
};
};
};
}
- Patterns in SOME – Command
- Patterns in SOME –State
- Patterns in SOME –Observer
- Patterns in SOME –Memento
- Patterns in SOME –Mediator
- Patterns in SOME –Iterator
- Patterns in SOME –Interpreter
- Patterns in SOME –Proxy
- Patterns in SOME –Flyweight
- Patterns in SOME –Facade
- Patterns in SOME –Decorator
- Patterns in SOME –Composite
- Patterns in SOME –Bridge
- Patterns in SOME –Singleton
- Patterns in SOME –Prototype
- Patterns in SOME –Builder
- Patterns in SOME –Chain Of Responsibility
- Patterns in SOME –Template Method
- [SilkTest]Overview of tags
- Linux(Unix)时钟同步ntpd服务配置方法
- 61条面向对象设计的经验原则
- session and cookie
- 中文意思:人家说着玩儿,你怎么就认起真来了.2006年日语等级报名网站、报名与考试时间!
- Patterns in SOME – Command
- 出现 org.hibernate.NonUniqueObjectException 错误的解决方法
- 把数据库文件变成XML文件
- WiMAX的主要优势及发展现状(news_20060801)
- 玩转brew菜单
- Sqlserver MD5 加密
- newxy标签实现访问控制
- 关于对栈溢出的分析
- 探讨两道.Net关于字符串的上机题