时间:2021-05-20
这个例子还是比较好理解的,所以只给出代码.
unitpattern;
interface
usesDialogs;
type
TAudioPlayer=class;
TCommand=class
public
procedureexecute;virtual;abstract;
end;
TPlayCommand=class(TCommand)
private
AudioPlayer:TAudioPlayer;
public
procedureexecute;override;
procedurePlaycommand(AP:TAudioPlayer);
end;
TStopCommand=class(TCommand)
private
AudioPlayer:TAudioPlayer;
public
procedureexecute;override;
procedureStopComman(AP:TAudioPlayer);
end;
TRewindCommand=class(TCommand)
private
AudioPlayer:TAudioPlayer;
public
procedureexecute;override;
procedureRewindCommand(AP:TAudioPlayer);
end;
TKeyPad=class
private
PlayCommand:TCommand;
StopCommand:TCommand;
RewindCommand:TCommand;
public
constructorCreate(PlayC,StopC,RewindC:TCommand);virtual;
procedureplay();
procedurestop();
procedurerewind();
end;
TAudioPlayer=class
public
procedureplay();
procedurestop();
procedurerewind();
end;
TClient=class
private
KeyPad:TKeyPad;
AudioPlayer:TAudioPlayer;
public
constructorCreate();
proceduretest();
end;
implementation
{TKeyPad}
constructorTKeyPad.Create(PlayC,StopC,RewindC:TCommand);
begin
PlayCommand:=PlayC;
StopCommand:=StopC;
RewindCommand:=RewindC;
end;
procedureTKeyPad.play;
begin
PlayCommand.execute;
end;
procedureTKeyPad.rewind;
begin
RewindCommand.execute;
end;
procedureTKeyPad.stop;
begin
StopCommand.execute;
end;
{TAudioPlayer}
procedureTAudioPlayer.play;
begin
ShowMessage(´play´);
end;
procedureTAudioPlayer.rewind;
begin
ShowMessage(´rewind´);
end;
procedureTAudioPlayer.stop;
begin
ShowMessage(´stop´);
end;
{TPlayCommand}
procedureTPlayCommand.execute;
begin
inherited;
AudioPlayer.play();
end;
procedureTPlayCommand.Playcommand(AP:TAudioPlayer);
begin
self.AudioPlayer:=AP;
end;
{TRewindCommand}
procedureTRewindCommand.execute;
begin
inherited;
AudioPlayer.Rewind;
end;
procedureTRewindCommand.RewindCommand(AP:TAudioPlayer);
begin
AudioPlayer:=ap;
end;
{TStopCommand}
procedureTStopCommand.execute;
begin
inherited;
AudioPlayer.Stop;
end;
procedureTStopCommand.StopComman(AP:TAudioPlayer);
begin
AudioPlayer:=ap;
end;
{TClient}
constructorTClient.Create;
begin
AudioPlayer:=TAudioPlayer.Create();
end;
procedureTClient.test;
var
PlayCommand:TCommand;
StopCommand:TCommand;
RewindCommand:TCommand;
begin
PlayCommand:=TPlayCommand.Create;
StopCommand:=TStopCommand.Create;
RewindCommand:=TRewindCommand.Create;
KeyPad:=TKeyPad.Create(PlayCommand,StopCommand,RewindCommand);
KeyPad.stop;
KeyPad.play;
KeyPad.rewind;
KeyPad.Stop;
end;
end.
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了PHP命令Command模式用法。分享给大家供大家参考,具体如下:命令Command模式是GOF23种模式中的一种,是一种行为模式。这种模式很难理
命令模式(Command),命令模式是封装一个通用操作的机制。如果你熟悉C或PHP,你可能已经遇到过Command,它相当于程序中的:回调(callback)。
在MacOS系统中,截图快捷键为“Shift+Command+4”。 用户只要同时按住键盘上的Shift键、Command键和数字4键,即可激活截图模式。
vi的两种命令模式;Command(命令)模式,用于输入命令;Insert(插入)模式,用于插入文本;Visual(可视)模式,用于视化的的高亮并选定正文;Co
一、mac电脑phpstorm快捷键command+a全选command+c复制command+v粘贴command+z撤消command+k代码搜索comma