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.

130 Case study: Design of a game<br />

Cell Add Add a counter to a cell.<br />

Display<br />

Display the contents of a cell.<br />

Flip<br />

Flip the contents of a cell.<br />

Holds<br />

Return the contents of a cell.<br />

Initialize<br />

Initialize a cell.<br />

Class Message Responsibility of method<br />

Counter Display<br />

Flip<br />

Rep<br />

Set<br />

Display a counter.<br />

Flip a counter.<br />

Return the colour of a counter.<br />

Set a counter to be black/white.<br />

Game Play Play the game.<br />

Note:<br />

9.3 Class diagram<br />

Some of the orig<strong>in</strong>al messages (verbs) have been renamed to a more specific name when produc<strong>in</strong>g this<br />

list.<br />

A class diagram for the game of draughts is shown below <strong>in</strong> Figure 9.4<br />

Player Counter Cell<br />

1 1 1 1<br />

2 64<br />

1<br />

Game<br />

1<br />

1<br />

Board<br />

1<br />

Figure 9.4 Relationship between the classes <strong>in</strong> the game of four counters.<br />

9.4 Specification of the <strong>Ada</strong> classes<br />

The <strong>Ada</strong> class specifications for the above classes are implemented as follows:<br />

Class<br />

Game<br />

<strong>Ada</strong> specification<br />

package Class_Game is<br />

type Game is private;<br />

procedure Play( The:<strong>in</strong> Game );<br />

private<br />

end Class_Counter;<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!