Теория и практика объектно-ориентированного программирования. Ноткин А.М. - 31 стр.

UptoLike

Составители: 

32
Объект-калькулятор, работающий с целыми числами: PInt = ^TInt;
TInt = object
private
EndState: byte;
public
x: integer;
Constructor Init (x1: integer);
Destructor Done; virtual;
Procedure GetEvent (Var Event: TEvent); virtual;
Procedure Execute; virtual;
Procedure HandleEvent (Var Event: TEvent); virtual;
Procedure ClearEvent (Var Event: TEvent); virtual;
Function Valid: boolean;
Procedure EndExec;
Function GetX: integer;
Procedure SetX (newX: integer);
Procedure AddY (Y: integer);
end;
Рассмотрим возможную реализацию основных методов:
Procedure TInit. GetEvent;
Const OpInt: set of char = [‘+’, ‘-’, ‘*’, ‘/’, ‘=’, ‘?’, ‘q’];
Var s: string;
code: char;
Begin
write(‘>’);
readln(s); code := s[1];
with Event do
if code in OpInt then begin
what:= evMessage;
case code of
‘+’: command:= cmAdd;
‘q’: command;= cmQuit;
end;
{выделить второй параметр, перевести его в тип integer и при-
своить полю A}
end
else what:= evNothing
End.
                                   32

     Объект-калькулятор, работающий с целыми числами: PInt = ^TInt;
     TInt = object
       private
         EndState: byte;
       public
         x: integer;
       Constructor Init (x1: integer);
       Destructor Done; virtual;
       Procedure GetEvent (Var Event: TEvent); virtual;
       Procedure Execute; virtual;
       Procedure HandleEvent (Var Event: TEvent); virtual;
       Procedure ClearEvent (Var Event: TEvent); virtual;
       Function Valid: boolean;
       Procedure EndExec;
       Function GetX: integer;
       Procedure SetX (newX: integer);
       Procedure AddY (Y: integer);
     …
     end;

     Рассмотрим возможную реализацию основных методов:
     Procedure TInit. GetEvent;
     Const OpInt: set of char = [‘+’, ‘-’, ‘*’, ‘/’, ‘=’, ‘?’, ‘q’];
     Var s: string;
          code: char;
     Begin
       write(‘>’);
       readln(s); code := s[1];
       with Event do
         if code in OpInt then begin
            what:= evMessage;
            case code of
              ‘+’: command:= cmAdd;
              …
              ‘q’: command;= cmQuit;
            end;
            {выделить второй параметр, перевести его в тип integer и при-
своить полю A}
         end
         else what:= evNothing
     End.