这个例子还是比较好理解的,所以只给出代码。
单位模式;
界面
使用对话框;
类型
TAudioPlayer=类;
TCommand=类
民众
程序执行;虚拟;抽象;
结尾;
TPlayCommand=类(TCommand)
私人的
音频播放器:TAudioPlayer;
民众
程序执行;覆盖;
procedurePlaycommand(AP:TAudioPlayer);
结尾;
TstopCommand=类(TCommand)
私人的
音频播放器:TAudioPlayer;
民众
程序执行;覆盖;
procedureStopComman(AP:TAudioPlayer);
结尾;
TRewindCommand=类(TCommand)
私人的
音频播放器:TAudioPlayer;
民众
程序执行;覆盖;
procedureRewindCommand(AP:TAudioPlayer);
结尾;
TKeyPad=类
私人的
播放命令:TCommand;
停止命令:TCommand;
倒带命令:TCommand;
民众
constructorCreate(PlayC,StopC,RewindC:TCommand);虚拟;
程序播放();
程序停止();
程序倒带();
结尾;
TAudioPlayer=类
民众
程序播放();
程序停止();
程序倒带();
结尾;
TClient=类
私人的
键盘:TKeyPad;
音频播放器:TAudioPlayer;
民众
构造函数Create();
程序测试();
结尾;
执行
{T键盘}
构造函数TKeyPad.Create(PlayC,StopC,RewindC:TCommand);
开始
播放命令:=PlayC;
停止命令:=停止C;
倒带命令:=倒带C;
结尾;
procedureTKeyPad.play;
开始
PlayCommand.执行;
结尾;
procedureTKeyPad.rewind;
开始
RewindCommand.execute;
结尾;
procedureTKeyPad.stop;
开始
停止命令.执行;
结尾;
{TAudio播放器}
程序TAudioPlayer.play;
开始
ShowMessage('播放');
结尾;
procedureTAudioPlayer.rewind;
开始
ShowMessage('倒带');
结尾;
procedureTAudioPlayer.stop;
开始
ShowMessage('停止');
结尾;
{T播放命令}
procedureTPlayCommand.execute;
开始
遗传;
AudioPlayer.play();
结尾;
procedureTPlayCommand.Playcommand(AP:TAudioPlayer);
开始
self.AudioPlayer:=AP;
结尾;
{TRewindCommand}
procedureTRewindCommand.execute;
开始
遗传;
AudioPlayer.倒带;
结尾;
procedureTRewindCommand.RewindCommand(AP:TAudioPlayer);
开始
音频播放器:= ap;
结尾;
{T停止命令}
procedureTStopCommand.execute;
开始
遗传;
AudioPlayer.Stop;
结尾;
procedureTStopCommand.StopComman(AP:TAudioPlayer);
开始
音频播放器:= ap;
结尾;
{T客户端}
构造函数TClient.Create;
开始
AudioPlayer:=TAudioPlayer.Create();
结尾;
procedureTClient.test;
变量
播放命令:TCommand;
停止命令:TCommand;
倒带命令:TCommand;
开始
PlayCommand:=TPlayCommand.Create;
StopCommand:=TstopCommand.Create;
RewindCommand:=TRewindCommand.Create;
KeyPad:=TKeyPad.Create(PlayCommand,StopCommand,RewindCommand);
键盘.停止;
键盘播放;
键盘.快退;
键盘.停止;
结尾;
结尾。