21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

140 Chapter 11 ■ Object-oriented design<br />

and testing time. It is common experience <strong>for</strong> someone setting out to write OO software<br />

to find that nearly all of the software already exists within the library. OO development<br />

is there<strong>for</strong>e often regarded as (merely) extending library classes. This, of<br />

course, requires a discipline – the initial investment in the time to explore and learn<br />

about what might be a large library, set against the benefits that accrue later.<br />

11.2 ● Design<br />

One of the principles used in the design of object-oriented software is to simulate real<br />

world situations as objects. You build a software model of things in the real world. Here<br />

are some examples:<br />

■ if we are developing an office in<strong>for</strong>mation system, we set out to simulate users, mail,<br />

shared documents and files<br />

■ in a factory automation system, we set out to simulate the different machines,<br />

queues of work, orders, and deliveries.<br />

The approach is to identify the objects in the problem to be addressed and to model<br />

them as objects in the software.<br />

One way to carry out OOD is to examine the software specification in order to<br />

extract in<strong>for</strong>mation about the objects and methods. The approach to identifying objects<br />

and methods is:<br />

1. look <strong>for</strong> nouns (things) in the specification – these are the objects<br />

2. look <strong>for</strong> verbs (doing words) in the specification – these are the methods<br />

Here is the specification <strong>for</strong> the cyberspace invaders program:<br />

A panel (Figure 11.1) displays a defender and an alien. The alien moves sideways.<br />

When it hits a wall, it reverses its direction. The alien randomly launches a bomb that<br />

moves vertically downwards. If a bomb hits the defender, the user loses and the game is<br />

over. The defender moves left or right according to mouse movements. When the mouse<br />

is clicked, the defender launches a laser that moves upwards. If a laser hits the alien, the<br />

user wins and the game is over.<br />

A button is provided to start a new game.<br />

Scanning through the specification, we find the following nouns. As we might<br />

expect, some of these nouns are mentioned more than once, but the repetition does not<br />

matter <strong>for</strong> the purpose of design.<br />

panel, defender, alien, wall, bomb, mouse, laser<br />

These nouns correspond to potential objects, and there<strong>for</strong>e classes within the program.<br />

So we translate these nouns into the names of classes in the model. The noun<br />

panel translates into the Panel class, available in the library. The nouns defender and<br />

alien translate into the classes Defender and Alien respectively. The noun wall

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!