18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The ma<strong>in</strong> body of the program processes the option selected by the user.<br />

Packages as classes 89<br />

beg<strong>in</strong><br />

loop<br />

Menu( Screen, "Deposit", "Withdraw", "Balance", "" );<br />

case Event( Screen ) is<br />

when M_1 =><br />

--Deposit<br />

Dialog( Screen, "Amount to deposit", Cash );<br />

if Cash <br />

--Withdraw<br />

Dialog( Screen, "Amount to withdraw", Cash );<br />

if Cash <br />

--Exit<br />

return;<br />

when others =><br />

--Not used<br />

end case;<br />

end loop;<br />

end Ma<strong>in</strong>;<br />

6.12 Class TUI<br />

Message( Screen, "Program error");<br />

The full specification for the class TUI is:<br />

--oops<br />

package Class_TUI is<br />

type Menu_Item is ( M_1, M_2, M_3, M_4, M_Quit );<br />

type TUI is private;<br />

procedure Menu( The:<strong>in</strong> out TUI; M1,M2,M3,M4:<strong>in</strong> Str<strong>in</strong>g );<br />

function Event( The:<strong>in</strong> TUI ) return Menu_Item;<br />

procedure Message( The:<strong>in</strong> TUI; Mes:<strong>in</strong> Str<strong>in</strong>g );<br />

procedure Dialog(The:<strong>in</strong> TUI; Mes:<strong>in</strong> Str<strong>in</strong>g; Res:out Float);<br />

procedure Dialog(The:<strong>in</strong> TUI; Mes:<strong>in</strong> Str<strong>in</strong>g; Res:out Integer);<br />

private<br />

type TUI is record<br />

Selection : Menu_Item := M_Quit;<br />

end record;<br />

end Class_TUI;<br />

In the implementation of the class TUI the most complex method is menu. This method is implemented as a<br />

procedure that writes out the menu for the TUI and reads the user’s response. It will only complete when a valid<br />

response has been received from the user. In the implementation of the procedure the technique of procedural<br />

decomposition is used to simplify the code.<br />

In procedural decomposition, a large body of code is split <strong>in</strong>to several procedures or functions. This helps to<br />

reduce complexity mak<strong>in</strong>g construction and ma<strong>in</strong>tenance easier.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!