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.

Polymorphism 237<br />

An example <strong>in</strong>teraction us<strong>in</strong>g the program would be as follows:<br />

Inquiry about room: 414<br />

414 4th Floor west w<strong>in</strong>g occupied by 2 people<br />

Inquiry about room: 422<br />

422 4th Floor east w<strong>in</strong>g<br />

Inquiry about room: 999<br />

Sorry room not known<br />

^D<br />

Note:<br />

The user’s <strong>in</strong>put is <strong>in</strong>dicated by bold type.<br />

16.6 Fully qualified names and polymorphism<br />

When us<strong>in</strong>g polymorphism and fully qualified names, the base class package name is used to qualify the<br />

polymorphic function or procedure. For example, the class Build<strong>in</strong>g specification could have been written as:<br />

with Class_Room, Class_Room.Build;<br />

package Class_Build<strong>in</strong>g is<br />

type Build<strong>in</strong>g is tagged private;<br />

procedure Add( The:<strong>in</strong> out Build<strong>in</strong>g;<br />

Desc:<strong>in</strong> Class_Room.Build.P_Room );<br />

function About(The:<strong>in</strong> Build<strong>in</strong>g; No:<strong>in</strong> Positive) return Str<strong>in</strong>g;<br />

private<br />

Max_Rooms : constant := 15;<br />

type Rooms_Index is range 0 .. Max_Rooms;<br />

subtype Rooms_Range is Rooms_Index range 1 .. Max_Rooms;<br />

type Rooms_Array is array (Rooms_Range) of<br />

Class_Room.Build.P_Room;<br />

type Build<strong>in</strong>g is tagged record<br />

Last : Rooms_Index := 0; --Last slot allocated<br />

Description : Rooms_Array; --Rooms <strong>in</strong> build<strong>in</strong>g<br />

end record;<br />

end Class_Build<strong>in</strong>g;<br />

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