This example is relatively well understood, so just give the code.
Unit pattern;
Interface
Uses Dialogs;
Type
Taudioplayer = class;
TCommand = Class
Public
Procedure Execute; Virtual Abstract
End
Tplaycommand = Class (TCommand)
Private
Audioplayer:taudioplayer;
Public
Procedure Execute; Override
Procedure Playcommand (Ap:taudioplayer);
End
Tstopcommand = Class (TCommand)
Private
Audioplayer:taudioplayer;
Public
Procedure Execute; Override
Procedure Stopcomman (Ap:taudioplayer);
End
Trewindcommand = Class (TCommand)
Private
Audioplayer:taudioplayer;
Public
Procedure Execute; Override
Procedure Rewindcommand (Ap:taudioplayer);
End
Tkeypad = Class
Private
Playcommand:tcommand;
Stopcommand:tcommand;
Rewindcommand:tcommand;
Public
Constructor Create (PLAYC, Stopc, Rewindc:tcommand); Virtual
Procedure play ();
Procedure Stop ();
Procedure Rewind ();
End
Taudioplayer = Class
Public
Procedure play ();
Procedure Stop ();
Procedure Rewind ();
End
TClient = Class
Private
Keypad:tkeypad;
Audioplayer:taudioplayer;
Public
Constructor Create ();
Procedure test ();
End
Implementation
{Tkeypad}
Constructor Tkeypad.create (PLAYC, Stopc, Rewindc:tcommand);
Begin
Playcommand: = PLAYC;
Stopcommand: = Stopc;
Rewindcommand: = REWINDC;
End
Procedure Tkeypad.play;
Begin
Playcommand.execute;
End
Procedure Tkeypad.rewind;
Begin
Rewindcommand.execute;
End
Procedure Tkeypad.stop;
Begin
Stopcommand.execute;
End
{Taudioplayer}
Procedure Taudioplayer.play;
Begin
ShowMessage (´play´);
End
Procedure Taudioplayer.rewind;
Begin
ShowMessage (´rewind´);
End
Procedure Taudioplayer.stop;
Begin
ShowMessage (´stop´);
End
{Tplaycommand}
Procedure Tplaycommand.execute;
Begin
inherited;
Audioplayer.play ();
End
Procedure Tplaycommand.playcommand (Ap:taudioplayer);
Begin
Self. Audioplayer: = AP;
End
{Trewindcommand}
Procedure Trewindcommand.execute;
Begin
inherited;
Audioplayer.rewind;
End
Procedure Trewindcommand.rewindcommand (Ap:taudioplayer);
Begin
Audioplayer: = AP;
End
{Tstopcommand}
Procedure Tstopcommand.execute;
Begin
inherited;
Audioplayer.stop;
End
Procedure Tstopcommand.stopcomman (Ap:taudioplayer);
Begin
Audioplayer: = AP;
End
{TClient}
Constructor Tclient.create;
Begin
Audioplayer: = Taudioplayer.create ();
End
Procedure Tclient.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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service