這個例子還是比較好理解的,所以只給代碼。
單位模式;
介面
使用對話框;
類型
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;
停止命令:=StopC;
倒帶指令:=倒帶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);
鍵盤.停止;
鍵盤播放;
鍵盤.快退;
鍵盤.停止;
結尾;
結尾。