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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Next we design and document the Alien class. The alien has a position and a size.<br />

Whenever the clock ticks, it moves. Its direction and speed is controlled by the step size<br />

that is used when it moves. It can be created and displayed.<br />

Class Alien<br />

Instance variables<br />

X<br />

Y<br />

height<br />

width<br />

xStep<br />

Methods<br />

Alien<br />

move<br />

display<br />

getX<br />

getY<br />

getHeight<br />

getWidth<br />

SELF-TEST QUESTION<br />

11.2 Write the class diagram <strong>for</strong> the Bomb class.<br />

We now have the full list of classes, and the methods and instance variables associated<br />

with each class – we have modeled the game and designed a structure <strong>for</strong> the program.<br />

11.3 ● Looking <strong>for</strong> reuse<br />

The next act of design is to check to make sure that we are not reinventing the wheel.<br />

One of the main benefits of OOP is reuse of software components. At this stage we<br />

should check whether:<br />

■ what we need might be in one of the libraries<br />

■ we may have written a class last month that is what we need<br />

■ we may be able to use inheritance.<br />

We see in the cyberspace invaders software can make good use of GUI components,<br />

such as the panel, available in the library. Other library components that are useful are<br />

a timer and a random number generator.<br />

If we find classes that are similar, we should think about using inheritance. We look<br />

at how to write the code to achieve inheritance in Chapter 15 on OOP. In Chapter 13<br />

on refactoring, we look at identifying inheritance using the “is-a” and “has-a” tests.

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

Saved successfully!

Ooh no, something went wrong!