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.

158 Inheritance<br />

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

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

package body Class_Named_Account is<br />

procedure Set( The:out Named_Account; Str:<strong>in</strong> Str<strong>in</strong>g ) is<br />

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

Set( The.Naa, Str );<br />

end Set;<br />

function Deliver_L<strong>in</strong>e( The:<strong>in</strong> Named_Account;<br />

L<strong>in</strong>e:<strong>in</strong> Positive ) return Str<strong>in</strong>g is<br />

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

return Deliver_L<strong>in</strong>e( The.Naa, L<strong>in</strong>e );<br />

end Deliver_L<strong>in</strong>e;<br />

function L<strong>in</strong>es( The:<strong>in</strong> Named_Account ) return Positive is<br />

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

return L<strong>in</strong>es( The.Naa );<br />

end L<strong>in</strong>es;<br />

The implementation of the methods <strong>in</strong> Named_Account which are <strong>in</strong>herited from Account are as follows:<br />

procedure Deposit(The:<strong>in</strong> out Named_Account; Amount:<strong>in</strong> Pmoney) is<br />

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

Deposit( The.Acc, Amount );<br />

end Deposit;<br />

procedure Withdraw( The:<strong>in</strong> out Named_Account; Amount:<strong>in</strong> Pmoney;<br />

Get:out Pmoney ) is<br />

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

Withdraw( The.Acc, Amount, Get );<br />

end Withdraw;<br />

function Balance ( The:<strong>in</strong> Named_Account ) return Pmoney is<br />

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

return Balance( The.Acc );<br />

end Balance;<br />

end Class_Named_Account;<br />

A procedure Statement to pr<strong>in</strong>t a m<strong>in</strong>i statement of the state of an <strong>in</strong>stance of a Named_Account is def<strong>in</strong>ed<br />

as follows:<br />

with <strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Float_Text_Io, Class_Named_Account;<br />

use <strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Float_Text_Io, Class_Named_Account;<br />

procedure Statement( An_Account:<strong>in</strong> Named_Account ) is<br />

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

Put("Statement for : " ); Put( Deliver_L<strong>in</strong>e(An_Account, 1)); New_L<strong>in</strong>e;<br />

Put("M<strong>in</strong>i statement: The amount on deposit is £" );<br />

Put( Balance( An_Account), Aft=>2, Exp=>0 );<br />

New_L<strong>in</strong>e(2);<br />

end Statement;<br />

Note: Aga<strong>in</strong> by not permit<strong>in</strong>g an <strong>in</strong>put or output operations to be part of the class, the scope for its potential<br />

re-use is <strong>in</strong>creased.<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!