November 2019
Beginner to intermediate
674 pages
15h
English
The last unexplored part of the program is the mechanism for creating copies of command objects (cloning). In this program, I went for a simple solution where each class implements the virtual function known as Clone, which knows how to create a perfect copy of the object. The following code fragment shows the implementation of this for four command classes:
function TCommand.Clone: TCommand;begin Result := TCommand.Create(Receiver);end;function TUndoableCommand.Clone: TCommand;begin Result := TUndoableCommand.Create(Receiver);end;function TKeyPressCommand.Clone: TCommand;begin Result := TKeyPressCommand.Create(Receiver, FKey);end;function TDeleteLeftCommand.Clone: TCommand;begin Result := TDeleteLeftCommand.Create(Receiver);end; ...
Read now
Unlock full access