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.

226 Polymorphism<br />

15.8 Self-assessment<br />

• What is an access type? What is an access value?<br />

• How is dynamic storage allocated?<br />

• What mechanisms are available to return dynamically allocated storage?<br />

• Why is dynamic storage allocation often considered a potential problem area <strong>in</strong> a program?<br />

• How do you pass a procedure as a parameter to another procedure?<br />

• Why is it essential to be able to call the procedure F<strong>in</strong>alize <strong>in</strong> the class Account more than once<br />

on the same object?<br />

• What is the difference between 'Access and 'Unchecked_Access?<br />

15.9 Exercises<br />

Construct the follow<strong>in</strong>g:<br />

• Store<br />

A store for data items which has as its generic parameters the type of the item stored and the type of the<br />

<strong>in</strong>dex used. The generic specification of the class is:<br />

generic<br />

type Store_<strong>in</strong>dex is private; --<br />

type Store_element is private; --<br />

package Class_store is<br />

type Store is limited private; -- NO copy<strong>in</strong>g<br />

Not_there, Full : exception;<br />

procedure add ( the:<strong>in</strong> out Store;<br />

<strong>in</strong>dex:<strong>in</strong> Store_<strong>in</strong>dex;<br />

item:<strong>in</strong> Store_element);<br />

function deliver( the:<strong>in</strong> Store;<br />

<strong>in</strong>dex:<strong>in</strong> Store_<strong>in</strong>dex )<br />

return Store_element;<br />

private<br />

--<br />

end Class_store;<br />

The implementation of the store uses a l<strong>in</strong>ked structure.<br />

• Queue<br />

The class Queue implements a data structure <strong>in</strong> which items are added to the rear of the queue and<br />

extracted from the front. Implement this generic class us<strong>in</strong>g dynamic storage allocation.<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!