这个例子还是比较好理解的,所以只给出代码.
patrón de unidad;
interfaz
utiliza cuadros de diálogo;
tipo
TAudioPlayer=clase;
TComando=clase
público
procedimientoejecutar;virtual;abstracto;
fin;
TPlayCommand=clase(TCommand)
privado
Reproductor de audio:TAudioPlayer;
público
ejecución de procedimiento; anulación;
procedimientoReproducircomando(AP:TAudioPlayer);
fin;
TStopCommand=clase(TCommand)
privado
Reproductor de audio:TAudioPlayer;
público
ejecución de procedimiento; anulación;
procedimientoStopComman(AP:TAudioPlayer);
fin;
TRewindCommand=clase(TCommand)
privado
Reproductor de audio:TAudioPlayer;
público
ejecución de procedimiento; anulación;
procedimientoRewindCommand(AP:TAudioPlayer);
fin;
TKeyPad=clase
privado
ReproducirComando:TCommand;
DetenerComando:TComando;
Comando de rebobinado: Comando T;
público
constructorCreate(PlayC,StopC,RewindC:TCommand);virtual;
juego de procedimientos();
procedimientosparar();
procedimientorebobinar();
fin;
TAudioPlayer=clase
público
juego de procedimientos();
procedimientosparar();
procedimientorebobinar();
fin;
Cliente T=clase
privado
Teclado: TKeyPad;
Reproductor de audio:TAudioPlayer;
público
constructorCrear();
prueba de procedimiento();
fin;
implementación
{TKeyPad}
constructorTKeyPad.Create(PlayC,StopC,RewindC:TCommand);
comenzar
ReproducirComando:=ReproducirC;
StopCommand:=PararC;
RebobinarComando:=RebobinarC;
fin;
procedimientoTKeyPad.play;
comenzar
PlayCommand.execute;
fin;
procedimientoTKeyPad.rewind;
comenzar
RewindCommand.execute;
fin;
procedimientoTKeyPad.stop;
comenzar
StopCommand.execute;
fin;
{TAudioPlayer}
procedimientoTAudioPlayer.play;
comenzar
MostrarMensaje('reproducir');
fin;
procedimientoTAudioPlayer.rebobinar;
comenzar
MostrarMensaje('rebobinar');
fin;
procedimientoTAudioPlayer.stop;
comenzar
MostrarMensaje(´detener´);
fin;
{TPlayCommand}
procedimientoTPlayCommand.execute;
comenzar
heredado;
AudioPlayer.play();
fin;
procedimientoTPlayCommand.Playcommand(AP:TAudioPlayer);
comenzar
self.AudioPlayer:=AP;
fin;
{TRewindComando}
procedimientoTRewindCommand.execute;
comenzar
heredado;
AudioPlayer.Rebobinar;
fin;
procedimientoTRewindCommand.RewindCommand(AP:TAudioPlayer);
comenzar
Reproductor de audio:=ap;
fin;
{TStopComando}
procedimientoTStopCommand.execute;
comenzar
heredado;
AudioPlayer.Detener;
fin;
procedimientoTStopCommand.StopComman(AP:TAudioPlayer);
comenzar
Reproductor de audio:=ap;
fin;
{TCliente}
constructorTClient.Create;
comenzar
Reproductor de audio:=TAudioPlayer.Create();
fin;
procedimientoTClient.test;
var
ReproducirComando:TCommand;
DetenerComando:TComando;
Comando de rebobinado: Comando T;
comenzar
PlayCommand:=TPlayCommand.Create;
StopCommand:=TStopCommand.Create;
RewindCommand:=TRewindCommand.Create;
Teclado:=TKeyPad.Create(PlayCommand,StopCommand,RewindCommand);
Teclado.parada;
Teclado.reproducir;
Teclado.rebobinar;
Teclado.Detener;
fin;
fin.