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.

Inheritance 157<br />

Note: The methods of the class Named_Account will be all the methods of an Account plus all the<br />

methods of Name_Address plus any methods of Named_Account itself.<br />

Unfortunately multiple <strong>in</strong>heritance is not directly supported <strong>in</strong> <strong>Ada</strong> <strong>95</strong>. However, an easy work around is to<br />

def<strong>in</strong>e the class Named_Account whose <strong>in</strong>stance attributes are <strong>in</strong>stances of the classes Account and<br />

Name_Address. The public methods of the class Named_Account have the same specification as the<br />

comb<strong>in</strong>ed methods of Account and Named_Account except that the type of object operated on is an <strong>in</strong>stance<br />

of the class Named_Account.<br />

The specification for the class Named_Account is shown below:<br />

with Class_Account, Class_Name_Address;<br />

use Class_Account, Class_Name_Address;<br />

package Class_Named_Account is<br />

type Named_Account is tagged private;<br />

subtype Pmoney is Class_Account.Pmoney;<br />

subtype Money is Class_Account.Money;<br />

procedure Set( The:out Named_Account; Str:<strong>in</strong> Str<strong>in</strong>g );<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;<br />

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

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

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

Get:out Pmoney );<br />

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

private<br />

type Named_Account is tagged record<br />

Acc : Account; --An account object<br />

Naa : Name_Address; --A Name and address object<br />

end record;<br />

end Class_Named_Account;<br />

Note:<br />

To allow a client of the class Named_Account to directly use the subtype Money <strong>in</strong> the class<br />

Account the declaration :<br />

subtype Money is Class_Account.Money;<br />

has been added to the class.<br />

The implementation of the class Named_Account is split <strong>in</strong>to three dist<strong>in</strong>ct parts:<br />

• The implementation of the methods <strong>in</strong> Name_Address.<br />

• The implementation of the methods <strong>in</strong> Account.<br />

• The implementation of the methods of Named_Account itself.<br />

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

follows:<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!