Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---命令模式之RemoteControlTest[转]

2020-12-13 15:36

阅读:529

标签:des   blog   http   io   ar   os   for   sp   div   

soscw.com,搜素材
  1soscw.com,搜素材
  2soscw.com,搜素材{《HeadFirst设计模式》之命令模式 }
  3soscw.com,搜素材{ 本单元中的类为命令的接收者      }
  4soscw.com,搜素材{ 编译工具 :Delphi7.0         }
  5soscw.com,搜素材{ 联系方式 :guzh-0417@163.com }
  6soscw.com,搜素材
  7soscw.com,搜素材unit uReceiveObject;
  8soscw.com,搜素材
  9soscw.com,搜素材interface
 10soscw.com,搜素材
 11soscw.com,搜素材type
 12soscw.com,搜素材  TLight = class(TObject)
 13soscw.com,搜素材  private
 14soscw.com,搜素材    FLocation: String;
 15soscw.com,搜素材  public
 16soscw.com,搜素材    constructor Create(aLocation: String);
 17soscw.com,搜素材    procedure Open;
 18soscw.com,搜素材    procedure Off;
 19soscw.com,搜素材  end;
 20soscw.com,搜素材
 21soscw.com,搜素材  TCeilingFan = class(TObject)
 22soscw.com,搜素材  private
 23soscw.com,搜素材    FLevel   : Integer;
 24soscw.com,搜素材    FLocation: String;
 25soscw.com,搜素材    function GetSpeed: Integer;
 26soscw.com,搜素材  public
 27soscw.com,搜素材    constructor Create(aLocation: String);
 28soscw.com,搜素材    procedure High;
 29soscw.com,搜素材    procedure Medium;
 30soscw.com,搜素材    procedure Low;
 31soscw.com,搜素材    procedure Off;
 32soscw.com,搜素材    property  Speed: Integer read GetSpeed;
 33soscw.com,搜素材  end;
 34soscw.com,搜素材
 35soscw.com,搜素材  TGarageDoor = class(TObject)
 36soscw.com,搜素材  private
 37soscw.com,搜素材    FLocation: String;
 38soscw.com,搜素材  public
 39soscw.com,搜素材    constructor Create(aLocation: String);
 40soscw.com,搜素材    procedure Up;
 41soscw.com,搜素材    procedure Down;
 42soscw.com,搜素材    procedure Stop;
 43soscw.com,搜素材    procedure LightOn;
 44soscw.com,搜素材    procedure LightOff;
 45soscw.com,搜素材  end;
 46soscw.com,搜素材
 47soscw.com,搜素材  TStereo = class(TObject)
 48soscw.com,搜素材  private
 49soscw.com,搜素材    FLocation: String;
 50soscw.com,搜素材  public
 51soscw.com,搜素材    constructor Create(aLocation: String);
 52soscw.com,搜素材    procedure Play;
 53soscw.com,搜素材    procedure Off;
 54soscw.com,搜素材    procedure SetCD;
 55soscw.com,搜素材    procedure SetDVD;
 56soscw.com,搜素材    procedure SetRadio;
 57soscw.com,搜素材    procedure SetVolume(aVolume: Integer);
 58soscw.com,搜素材  end;
 59soscw.com,搜素材
 60soscw.com,搜素材  TTV = class(TObject)
 61soscw.com,搜素材  private
 62soscw.com,搜素材    FLocation: String;
 63soscw.com,搜素材    FChannel : Integer;
 64soscw.com,搜素材  public
 65soscw.com,搜素材    constructor Create(aLocation: String);
 66soscw.com,搜素材    procedure Open;
 67soscw.com,搜素材    procedure Off;
 68soscw.com,搜素材    procedure SetInputChannel;
 69soscw.com,搜素材  end;
 70soscw.com,搜素材
 71soscw.com,搜素材  THottub = class(TObject)
 72soscw.com,搜素材  private
 73soscw.com,搜素材    FOpen: Boolean;
 74soscw.com,搜素材    FTemp: Integer;
 75soscw.com,搜素材    function  GetTemp: Integer;
 76soscw.com,搜素材    procedure SetTemp(const Value: Integer);
 77soscw.com,搜素材  public
 78soscw.com,搜素材    function  Open: Boolean;
 79soscw.com,搜素材    function  Off : Boolean;
 80soscw.com,搜素材    procedure BubblesOpen;
 81soscw.com,搜素材    procedure BubblesOff;
 82soscw.com,搜素材    procedure JetsOpen;
 83soscw.com,搜素材    procedure JetsOff;
 84soscw.com,搜素材    procedure Heat;
 85soscw.com,搜素材    procedure Cool;
 86soscw.com,搜素材    property  Temp: Integer read GetTemp write SetTemp;
 87soscw.com,搜素材  end;
 88soscw.com,搜素材  
 89soscw.com,搜素材implementation
 90soscw.com,搜素材
 91soscw.com,搜素材const
 92soscw.com,搜素材  SPEED_HIGH   = 2;
 93soscw.com,搜素材  SPEED_MEDIUM = 1;
 94soscw.com,搜素材  SPEED_LOW    = 0;
 95soscw.com,搜素材
 96soscw.com,搜素材{ TLight }
 97soscw.com,搜素材
 98soscw.com,搜素材constructor TLight.Create(aLocation: String);
 99soscw.com,搜素材begin
100soscw.com,搜素材  FLocation := aLocation;
101soscw.com,搜素材end;
102soscw.com,搜素材
103soscw.com,搜素材procedure TLight.Off;
104soscw.com,搜素材begin
105soscw.com,搜素材  Writeln(FLocation + ‘Light is off.‘);
106soscw.com,搜素材end;
107soscw.com,搜素材
108soscw.com,搜素材procedure TLight.Open;
109soscw.com,搜素材begin
110soscw.com,搜素材  Writeln(FLocation + ‘Light is on.‘);
111soscw.com,搜素材end;
112soscw.com,搜素材
113soscw.com,搜素材{ TCeilingFan }
114soscw.com,搜素材
115soscw.com,搜素材constructor TCeilingFan.Create(aLocation: String);
116soscw.com,搜素材begin
117soscw.com,搜素材  FLocation := aLocation;
118soscw.com,搜素材end;
119soscw.com,搜素材
120soscw.com,搜素材function TCeilingFan.GetSpeed: Integer;
121soscw.com,搜素材begin
122soscw.com,搜素材  Result := FLevel;
123soscw.com,搜素材end;
124soscw.com,搜素材
125soscw.com,搜素材procedure TCeilingFan.High;
126soscw.com,搜素材begin
127soscw.com,搜素材  FLevel := SPEED_HIGH;
128soscw.com,搜素材  Writeln(FLocation + ‘Ceiling fan is on high.‘);
129soscw.com,搜素材end;
130soscw.com,搜素材
131soscw.com,搜素材procedure TCeilingFan.Low;
132soscw.com,搜素材begin
133soscw.com,搜素材  FLevel := SPEED_LOW;
134soscw.com,搜素材  Writeln(FLocation + ‘Ceiling fan is on low.‘);
135soscw.com,搜素材end;
136soscw.com,搜素材
137soscw.com,搜素材procedure TCeilingFan.Medium;
138soscw.com,搜素材begin
139soscw.com,搜素材  FLevel := SPEED_MEDIUM;
140soscw.com,搜素材  Writeln(FLocation + ‘Ceiling fan is on medium.‘);
141soscw.com,搜素材end;
142soscw.com,搜素材
143soscw.com,搜素材procedure TCeilingFan.Off;
144soscw.com,搜素材begin
145soscw.com,搜素材  FLevel := 0;
146soscw.com,搜素材  Writeln(FLocation + ‘Ceiling fan is on off.‘);
147soscw.com,搜素材end;
148soscw.com,搜素材
149soscw.com,搜素材{ TGarageDoor }
150soscw.com,搜素材
151soscw.com,搜素材constructor TGarageDoor.Create(aLocation: String);
152soscw.com,搜素材begin
153soscw.com,搜素材  FLocation := aLocation;
154soscw.com,搜素材end;
155soscw.com,搜素材
156soscw.com,搜素材procedure TGarageDoor.Down;
157soscw.com,搜素材begin
158soscw.com,搜素材  Writeln(FLocation + ‘Garage door is down.‘);
159soscw.com,搜素材end;
160soscw.com,搜素材
161soscw.com,搜素材procedure TGarageDoor.LightOff;
162soscw.com,搜素材begin
163soscw.com,搜素材  Writeln(FLocation + ‘Garage light is off.‘);
164soscw.com,搜素材end;
165soscw.com,搜素材
166soscw.com,搜素材procedure TGarageDoor.LightOn;
167soscw.com,搜素材begin
168soscw.com,搜素材  Writeln(FLocation + ‘Garage light is on.‘);
169soscw.com,搜素材end;
170soscw.com,搜素材
171soscw.com,搜素材procedure TGarageDoor.Stop;
172soscw.com,搜素材begin
173soscw.com,搜素材  Writeln(FLocation + ‘Garage door is stopped.‘);
174soscw.com,搜素材end;
175soscw.com,搜素材
176soscw.com,搜素材procedure TGarageDoor.Up;
177soscw.com,搜素材begin
178soscw.com,搜素材  Writeln(FLocation + ‘Garage door is up.‘);
179soscw.com,搜素材end;
180soscw.com,搜素材
181soscw.com,搜素材{ TStereo }
182soscw.com,搜素材
183soscw.com,搜素材constructor TStereo.Create(aLocation: String);
184soscw.com,搜素材begin
185soscw.com,搜素材  FLocation := aLocation;
186soscw.com,搜素材end;
187soscw.com,搜素材
188soscw.com,搜素材procedure TStereo.Off;
189soscw.com,搜素材begin
190soscw.com,搜素材  Writeln(FLocation + ‘Stereo is off.‘);
191soscw.com,搜素材end;
192soscw.com,搜素材
193soscw.com,搜素材procedure TStereo.Play;
194soscw.com,搜素材begin
195soscw.com,搜素材  Writeln(FLocation + ‘Stereo is on.‘);
196soscw.com,搜素材end;
197soscw.com,搜素材
198soscw.com,搜素材procedure TStereo.SetCD;
199soscw.com,搜素材begin
200soscw.com,搜素材  Writeln(FLocation + ‘Stereo is set for CD input.‘);
201soscw.com,搜素材end;
202soscw.com,搜素材
203soscw.com,搜素材procedure TStereo.SetDVD;
204soscw.com,搜素材begin
205soscw.com,搜素材  Writeln(FLocation + ‘Stereo is set for DVD input.‘);
206soscw.com,搜素材end;
207soscw.com,搜素材
208soscw.com,搜素材procedure TStereo.SetRadio;
209soscw.com,搜素材begin
210soscw.com,搜素材  Writeln(FLocation + ‘Stereo is set for radio.‘);
211soscw.com,搜素材end;
212soscw.com,搜素材
213soscw.com,搜素材procedure TStereo.SetVolume(aVolume: Integer);
214soscw.com,搜素材begin
215soscw.com,搜素材  Writeln(FLocation + ‘Stereo volume set to ‘, aVolume);
216soscw.com,搜素材end;
217soscw.com,搜素材
218soscw.com,搜素材{ TTV }
219soscw.com,搜素材
220soscw.com,搜素材constructor TTV.Create(aLocation: String);
221soscw.com,搜素材begin
222soscw.com,搜素材  FLocation := aLocation;
223soscw.com,搜素材end;
224soscw.com,搜素材
225soscw.com,搜素材procedure TTV.Off;
226soscw.com,搜素材begin
227soscw.com,搜素材  Writeln(FLocation + ‘TV is off.‘);
228soscw.com,搜素材end;
229soscw.com,搜素材
230soscw.com,搜素材procedure TTV.Open;
231soscw.com,搜素材begin
232soscw.com,搜素材  Writeln(FLocation + ‘TV is on.‘);
233soscw.com,搜素材end;
234soscw.com,搜素材
235soscw.com,搜素材procedure TTV.SetInputChannel;
236soscw.com,搜素材begin
237soscw.com,搜素材  FChannel := 3;
238soscw.com,搜素材  Writeln(‘Channel is set for VCR.‘);
239soscw.com,搜素材end;
240soscw.com,搜素材
241soscw.com,搜素材{ THottub }
242soscw.com,搜素材
243soscw.com,搜素材procedure THottub.BubblesOff;
244soscw.com,搜素材begin
245soscw.com,搜素材  if Off then
246soscw.com,搜素材    Writeln(‘Hottub is not bubbling.‘);
247soscw.com,搜素材end;
248soscw.com,搜素材
249soscw.com,搜素材procedure THottub.BubblesOpen;
250soscw.com,搜素材begin
251soscw.com,搜素材  if Open then
252soscw.com,搜素材    Writeln(‘Hottub is bubbling.‘);
253soscw.com,搜素材end;
254soscw.com,搜素材
255soscw.com,搜素材procedure THottub.Cool;
256soscw.com,搜素材begin
257soscw.com,搜素材  FTemp := 98;
258soscw.com,搜素材  Writeln(‘Hottub is cooling to 98 degrees.‘);
259soscw.com,搜素材end;
260soscw.com,搜素材
261soscw.com,搜素材function THottub.GetTemp: Integer;
262soscw.com,搜素材begin
263soscw.com,搜素材  Result := FTemp;
264soscw.com,搜素材end;
265soscw.com,搜素材
266soscw.com,搜素材procedure THottub.Heat;
267soscw.com,搜素材begin
268soscw.com,搜素材  FTemp := 105;
269soscw.com,搜素材  Writeln(‘Hottub is heating to a steaming 105 degrees.‘);
270soscw.com,搜素材end;
271soscw.com,搜素材
272soscw.com,搜素材procedure THottub.JetsOff;
273soscw.com,搜素材begin
274soscw.com,搜素材  if Off then
275soscw.com,搜素材    Writeln(‘Hottub jets are off.‘);
276soscw.com,搜素材end;
277soscw.com,搜素材
278soscw.com,搜素材procedure THottub.JetsOpen;
279soscw.com,搜素材begin
280soscw.com,搜素材  if Open then
281soscw.com,搜素材    Writeln(‘Hottub jets are open.‘);
282soscw.com,搜素材end;
283soscw.com,搜素材
284soscw.com,搜素材function THottub.Off:  Boolean;
285soscw.com,搜素材begin
286soscw.com,搜素材  FOpen  := False;
287soscw.com,搜素材  Result := FOpen;
288soscw.com,搜素材end;
289soscw.com,搜素材
290soscw.com,搜素材function THottub.Open: Boolean;
291soscw.com,搜素材begin
292soscw.com,搜素材  FOpen  := True;
293soscw.com,搜素材  Result := FOpen;
294soscw.com,搜素材end;
295soscw.com,搜素材
296soscw.com,搜素材procedure THottub.SetTemp(const Value: Integer);
297soscw.com,搜素材begin
298soscw.com,搜素材  FTemp := Value;
299soscw.com,搜素材end;
300soscw.com,搜素材
301soscw.com,搜素材end.

 

 

soscw.com,搜素材
  1soscw.com,搜素材
  2soscw.com,搜素材{《HeadFirst设计模式》之命令模式     }
  3soscw.com,搜素材{ 将命令接收者中的动作包装成命令对象 }
  4soscw.com,搜素材{ 编译工具 :Delphi7.0               }
  5soscw.com,搜素材{ 联系方式 :guzh-0417@163.com       }
  6soscw.com,搜素材
  7soscw.com,搜素材unit uCommandObject;
  8soscw.com,搜素材
  9soscw.com,搜素材interface
 10soscw.com,搜素材
 11soscw.com,搜素材uses
 12soscw.com,搜素材  uReceiveObject;
 13soscw.com,搜素材
 14soscw.com,搜素材type
 15soscw.com,搜素材  TCommand = class(TObject)
 16soscw.com,搜素材  public
 17soscw.com,搜素材    procedure Execute; virtual; abstract;
 18soscw.com,搜素材  end;
 19soscw.com,搜素材
 20soscw.com,搜素材  TNoCommand = class(TCommand)
 21soscw.com,搜素材  public
 22soscw.com,搜素材    procedure Execute; override;
 23soscw.com,搜素材  end;
 24soscw.com,搜素材
 25soscw.com,搜素材  TLightOnCommand = class(TCommand)
 26soscw.com,搜素材  private
 27soscw.com,搜素材    FLight: TLight;
 28soscw.com,搜素材  public
 29soscw.com,搜素材    constructor Create(aLight: TLight);
 30soscw.com,搜素材    procedure Execute; override;
 31soscw.com,搜素材  end;
 32soscw.com,搜素材
 33soscw.com,搜素材  TLightOffCommand = class(TCommand)
 34soscw.com,搜素材  protected
 35soscw.com,搜素材    FLight: TLight;
 36soscw.com,搜素材  public
 37soscw.com,搜素材    constructor Create(aLight: TLight);
 38soscw.com,搜素材    procedure Execute; override;
 39soscw.com,搜素材  end;
 40soscw.com,搜素材
 41soscw.com,搜素材  TLivingRoomLightOnCommand = class(TLightOnCommand)
 42soscw.com,搜素材  end;
 43soscw.com,搜素材
 44soscw.com,搜素材  TLivingRoomLightOffCommand = class(TLightOffCommand)
 45soscw.com,搜素材  end;
 46soscw.com,搜素材
 47soscw.com,搜素材  TKitchenLightOnCommand = class(TLightOnCommand)
 48soscw.com,搜素材  end;
 49soscw.com,搜素材
 50soscw.com,搜素材  TKitchenLightOffCommand = class(TLightOffCommand)
 51soscw.com,搜素材  end;
 52soscw.com,搜素材
 53soscw.com,搜素材  TCeilingFanOnCommand = class(TCommand)
 54soscw.com,搜素材  private
 55soscw.com,搜素材    FCeilingFan: TCeilingFan;
 56soscw.com,搜素材  public
 57soscw.com,搜素材    constructor Create(aCeilingFan: TCeilingFan);
 58soscw.com,搜素材    procedure Execute; override;
 59soscw.com,搜素材  end;
 60soscw.com,搜素材
 61soscw.com,搜素材  TCeilingFanOffCommand = class(TCommand)
 62soscw.com,搜素材  private
 63soscw.com,搜素材    FCeilingFan: TCeilingFan;
 64soscw.com,搜素材  public
 65soscw.com,搜素材    constructor Create(aCeilingFan: TCeilingFan);
 66soscw.com,搜素材    procedure Execute; override;
 67soscw.com,搜素材  end;
 68soscw.com,搜素材
 69soscw.com,搜素材  TGarageDoorUpCommand = class(TCommand)
 70soscw.com,搜素材  private
 71soscw.com,搜素材    FGarageDoor: TGarageDoor;
 72soscw.com,搜素材  public
 73soscw.com,搜素材    constructor Create(aGarageDoor: TGarageDoor);
 74soscw.com,搜素材    procedure Execute; override;
 75soscw.com,搜素材  end;
 76soscw.com,搜素材
 77soscw.com,搜素材  TGarageDoorDownCommand = class(TCommand)
 78soscw.com,搜素材  private
 79soscw.com,搜素材    FGarageDoor: TGarageDoor;
 80soscw.com,搜素材  public
 81soscw.com,搜素材    constructor Create(aGarageDoor: TGarageDoor);
 82soscw.com,搜素材    procedure Execute; override;
 83soscw.com,搜素材  end;
 84soscw.com,搜素材
 85soscw.com,搜素材  TStereoOnWithCDCommand = class(TCommand)
 86soscw.com,搜素材  private
 87soscw.com,搜素材    FStereo: TStereo;
 88soscw.com,搜素材  public
 89soscw.com,搜素材    constructor Create(aStereo: TStereo);
 90soscw.com,搜素材    procedure Execute; override;
 91soscw.com,搜素材  end;
 92soscw.com,搜素材
 93soscw.com,搜素材  TStereoOffCommand = class(TCommand)
 94soscw.com,搜素材  private
 95soscw.com,搜素材    FStereo: TStereo;
 96soscw.com,搜素材  public
 97soscw.com,搜素材    constructor Create(aStereo: TStereo);
 98soscw.com,搜素材    procedure Execute; override;
 99soscw.com,搜素材  end;
100soscw.com,搜素材
101soscw.com,搜素材  THottubOnCommand = class(TCommand)
102soscw.com,搜素材  private
103soscw.com,搜素材    FHottub: THottub;
104soscw.com,搜素材  public
105soscw.com,搜素材    constructor Create(aHottub: THottub);
106soscw.com,搜素材    procedure Execute; override;
107soscw.com,搜素材  end;
108soscw.com,搜素材
109soscw.com,搜素材  THottubOffCommand = class(TCommand)
110soscw.com,搜素材  private
111soscw.com,搜素材    FHottub: THottub;
112soscw.com,搜素材  public
113soscw.com,搜素材    constructor Create(aHottub: THottub);
114soscw.com,搜素材    procedure Execute; override;
115soscw.com,搜素材  end;
116soscw.com,搜素材
117soscw.com,搜素材implementation
118soscw.com,搜素材
119soscw.com,搜素材{ TNoCommand }
120soscw.com,搜素材
121soscw.com,搜素材procedure TNoCommand.Execute;
122soscw.com,搜素材begin
123soscw.com,搜素材end;
124soscw.com,搜素材
125soscw.com,搜素材{ TLightOnCommand }
126soscw.com,搜素材
127soscw.com,搜素材constructor TLightOnCommand.Create(aLight: TLight);
128soscw.com,搜素材begin
129soscw.com,搜素材  FLight := aLight;
130soscw.com,搜素材end;
131soscw.com,搜素材
132soscw.com,搜素材procedure TLightOnCommand.Execute;
133soscw.com,搜素材begin
134soscw.com,搜素材  FLight.Open;
135soscw.com,搜素材end;
136soscw.com,搜素材
137soscw.com,搜素材{ TLightOffCommand }
138soscw.com,搜素材
139soscw.com,搜素材constructor TLightOffCommand.Create(aLight: TLight);
140soscw.com,搜素材begin
141soscw.com,搜素材  FLight := aLight;
142soscw.com,搜素材end;
143soscw.com,搜素材
144soscw.com,搜素材procedure TLightOffCommand.Execute;
145soscw.com,搜素材begin
146soscw.com,搜素材  FLight.Off;
147soscw.com,搜素材end;
148soscw.com,搜素材
149soscw.com,搜素材
150soscw.com,搜素材
151soscw.com,搜素材{ TLivingRoomLightOnCommand }
152soscw.com,搜素材
153soscw.com,搜素材{ TLivingRoomLightOffCommand }
154soscw.com,搜素材
155soscw.com,搜素材{ TKitchenLightOnCommand }
156soscw.com,搜素材
157soscw.com,搜素材{ TKitchenLightOffCommand }
158soscw.com,搜素材
159soscw.com,搜素材
160soscw.com,搜素材
161soscw.com,搜素材{ TCeilingFanOnCommand }
162soscw.com,搜素材
163soscw.com,搜素材constructor TCeilingFanOnCommand.Create(aCeilingFan: TCeilingFan);
164soscw.com,搜素材begin
165soscw.com,搜素材  FCeilingFan := aCeilingFan;
166soscw.com,搜素材end;
167soscw.com,搜素材
168soscw.com,搜素材procedure TCeilingFanOnCommand.Execute;
169soscw.com,搜素材begin
170soscw.com,搜素材  FCeilingFan.High;
171soscw.com,搜素材end;
172soscw.com,搜素材
173soscw.com,搜素材{ TCeilingFanOffCommand }
174soscw.com,搜素材
175soscw.com,搜素材constructor TCeilingFanOffCommand.Create(aCeilingFan: TCeilingFan);
176soscw.com,搜素材begin
177soscw.com,搜素材  FCeilingFan := aCeilingFan;
178soscw.com,搜素材end;
179soscw.com,搜素材
180soscw.com,搜素材procedure TCeilingFanOffCommand.Execute;
181soscw.com,搜素材begin
182soscw.com,搜素材  FCeilingFan.Off;
183soscw.com,搜素材end;
184soscw.com,搜素材
185soscw.com,搜素材{ TGarageDoorUpCommand }
186soscw.com,搜素材
187soscw.com,搜素材constructor TGarageDoorUpCommand.Create(aGarageDoor: TGarageDoor);
188soscw.com,搜素材begin
189soscw.com,搜素材  FGarageDoor := aGarageDoor;
190soscw.com,搜素材end;
191soscw.com,搜素材
192soscw.com,搜素材procedure TGarageDoorUpCommand.Execute;
193soscw.com,搜素材begin
194soscw.com,搜素材  FGarageDoor.Up;
195soscw.com,搜素材  FGarageDoor.LightOn;
196soscw.com,搜素材end;
197soscw.com,搜素材
198soscw.com,搜素材{ TGarageDoorDownCommand }
199soscw.com,搜素材
200soscw.com,搜素材constructor TGarageDoorDownCommand.Create(aGarageDoor: TGarageDoor);
201soscw.com,搜素材begin
202soscw.com,搜素材  FGarageDoor := aGarageDoor;
203soscw.com,搜素材end;
204soscw.com,搜素材
205soscw.com,搜素材procedure TGarageDoorDownCommand.Execute;
206soscw.com,搜素材begin
207soscw.com,搜素材  FGarageDoor.Down;
208soscw.com,搜素材  FGarageDoor.LightOff;
209soscw.com,搜素材end;
210soscw.com,搜素材
211soscw.com,搜素材{ TStereoOnWithCDCommand }
212soscw.com,搜素材
213soscw.com,搜素材constructor TStereoOnWithCDCommand.Create(aStereo: TStereo);
214soscw.com,搜素材begin
215soscw.com,搜素材  FStereo := aStereo;
216soscw.com,搜素材end;
217soscw.com,搜素材
218soscw.com,搜素材procedure TStereoOnWithCDCommand.Execute;
219soscw.com,搜素材begin
220soscw.com,搜素材  FStereo.Play;
221soscw.com,搜素材  FStereo.SetCD;
222soscw.com,搜素材  FStereo.SetVolume(11);
223soscw.com,搜素材end;
224soscw.com,搜素材
225soscw.com,搜素材{ TStereoOffCommand }
226soscw.com,搜素材
227soscw.com,搜素材constructor TStereoOffCommand.Create(aStereo: TStereo);
228soscw.com,搜素材begin
229soscw.com,搜素材  FStereo := aStereo;
230soscw.com,搜素材end;
231soscw.com,搜素材
232soscw.com,搜素材procedure TStereoOffCommand.Execute;
233soscw.com,搜素材begin
234soscw.com,搜素材  FStereo.Off;
235soscw.com,搜素材end;
236soscw.com,搜素材
237soscw.com,搜素材{ THottubOnCommand }
238soscw.com,搜素材
239soscw.com,搜素材constructor THottubOnCommand.Create(aHottub: Thottub);
240soscw.com,搜素材begin
241soscw.com,搜素材  FHottub := aHottub;
242soscw.com,搜素材end;
243soscw.com,搜素材
244soscw.com,搜素材procedure THottubOnCommand.Execute;
245soscw.com,搜素材begin
246soscw.com,搜素材  FHottub.Open;
247soscw.com,搜素材  FHottub.Heat;
248soscw.com,搜素材  FHottub.BubblesOpen;
249soscw.com,搜素材  FHottub.JetsOpen;
250soscw.com,搜素材end;
251soscw.com,搜素材
252soscw.com,搜素材{ THottubOffCommand }
253soscw.com,搜素材
254soscw.com,搜素材constructor THottubOffCommand.Create(aHottub: THottub);
255soscw.com,搜素材begin
256soscw.com,搜素材  FHottub := aHottub;
257soscw.com,搜素材end;
258soscw.com,搜素材
259soscw.com,搜素材procedure THottubOffCommand.Execute;
260soscw.com,搜素材begin
261soscw.com,搜素材  FHottub.Cool;
262soscw.com,搜素材  FHottub.Off;
263soscw.com,搜素材end;
264soscw.com,搜素材
265soscw.com,搜素材end.

 

 

soscw.com,搜素材
 1soscw.com,搜素材
 2soscw.com,搜素材{《HeadFirst设计模式》之命令模式                  }
 3soscw.com,搜素材{ 本单元中的类为命令的请求者,向命令对象发出请求,}
 4soscw.com,搜素材{ 命令对象通过委托,执行命令接收者中的动作。      }
 5soscw.com,搜素材{ 编译工具 :Delphi7.0                            }
 6soscw.com,搜素材{ 联系方式 :guzh-0417@163.com                    }
 7soscw.com,搜素材
 8soscw.com,搜素材unit uInvoker;
 9soscw.com,搜素材
10soscw.com,搜素材interface
11soscw.com,搜素材
12soscw.com,搜素材uses
13soscw.com,搜素材  uCommandObject;
14soscw.com,搜素材
15soscw.com,搜素材type
16soscw.com,搜素材  TRemoteControl = class(TObject)
17soscw.com,搜素材  private
18soscw.com,搜素材    FOnCommands : array of TCommand;
19soscw.com,搜素材    FOffCommands: array of TCommand;
20soscw.com,搜素材    FNoCommand  : TCommand;
21soscw.com,搜素材  public
22soscw.com,搜素材    constructor Create;
23soscw.com,搜素材    destructor  Destroy;


评论


亲,登录后才可以留言!