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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Exceptions 167<br />

11.1.1 Putt<strong>in</strong>g it all together<br />

The package Interest_account and its child <strong>in</strong>spect_<strong>in</strong>terest are used as follows:<br />

with <strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Float_Text_Io, Class_Account,<br />

Class_Interest_Account, Class_Interest_Account.Inspect_Interest,<br />

Statement;<br />

use <strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Float_Text_Io, Class_Account,<br />

Class_Interest_Account, Class_Interest_Account.Inspect_Interest;<br />

procedure Ma<strong>in</strong> is<br />

My_Account: Interest_Account;<br />

Obta<strong>in</strong>ed : Money;<br />

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

Statement( My_Account );<br />

Put("Deposit 100.00 <strong>in</strong>to account"); New_L<strong>in</strong>e;<br />

Deposit( My_Account, 100.00 ); --Day 1<br />

Calc_Interest( My_Account ); --End of day 1<br />

Calc_Interest( My_Account ); --End of day 2<br />

Statement( My_Account ); --Day 3<br />

Obta<strong>in</strong>ed := Interest_Is( My_Account ); --How much <strong>in</strong>terest<br />

Put("Interest accrued so far : £" );<br />

Put( Obta<strong>in</strong>ed, Aft=>2, Exp=>0 ); New_L<strong>in</strong>e;<br />

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

Note: When a child is <strong>in</strong>cluded, its ancestors are automatically with’ed.<br />

When run it will produce the follow<strong>in</strong>g output:<br />

M<strong>in</strong>i statement: The amount on deposit is £ 0.00<br />

Deposit 100.00 <strong>in</strong>to account<br />

M<strong>in</strong>i statement: The amount on deposit is £100.00<br />

Interest accrued so far : £ 0.05<br />

11.1.2 Warn<strong>in</strong>g<br />

A child package breaks the encapsulation rules of a package. In particular a child package can access the private<br />

data components of its parent package. In access<strong>in</strong>g the private <strong>in</strong>stance attributes of a class, the child package<br />

may compromise the <strong>in</strong>tegrity of the parent package.<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!