Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach

web.firat.edu.tr
from web.firat.edu.tr More from this publisher
21.08.2013 Views

SELF-TEST QUESTION 11.1 Derive information about objects and methods from the use case: ■ laser hits alien – when a laser hits the alien, the player wins. 11.2 Design 143 While we are identifying classes and methods, we can document each class as a UML class diagram. This type of class diagram shows more detail about a class than those we have met so far. A large rectangle contains three sections. The first section simply shows the class name. The second section shows the instance variables. The third section shows the public methods provided by the class. We start with class Game: class Game Instance variables panel timer Methods mouseMoved mouseClicked actionPerformed Next we consider the defender object. It has a position within the panel and a size. In response to a mouse movement, it moves. It can be displayed. Therefore its class diagram is: class Defender Instance variables x y height width Methods move display getX getY getHeight getWidth

144 Chapter 11 ■ Object-oriented design Next we design and document the Alien class. The alien has a position and a size. Whenever the clock ticks, it moves. Its direction and speed is controlled by the step size that is used when it moves. It can be created and displayed. Class Alien Instance variables X Y height width xStep Methods Alien move display getX getY getHeight getWidth SELF-TEST QUESTION 11.2 Write the class diagram for the Bomb class. We now have the full list of classes, and the methods and instance variables associated with each class – we have modeled the game and designed a structure for the program. 11.3 ● Looking for reuse The next act of design is to check to make sure that we are not reinventing the wheel. One of the main benefits of OOP is reuse of software components. At this stage we should check whether: ■ what we need might be in one of the libraries ■ we may have written a class last month that is what we need ■ we may be able to use inheritance. We see in the cyberspace invaders software can make good use of GUI components, such as the panel, available in the library. Other library components that are useful are a timer and a random number generator. If we find classes that are similar, we should think about using inheritance. We look at how to write the code to achieve inheritance in Chapter 15 on OOP. In Chapter 13 on refactoring, we look at identifying inheritance using the “is-a” and “has-a” tests.

SELF-TEST QUESTION<br />

11.1 Derive in<strong>for</strong>mation about objects and methods from the use case:<br />

■ laser hits alien – when a laser hits the alien, the player wins.<br />

11.2 Design 143<br />

While we are identifying classes and methods, we can document each class as a UML<br />

class diagram. This type of class diagram shows more detail about a class than those we<br />

have met so far. A large rectangle contains three sections. The first section simply shows<br />

the class name. The second section shows the instance variables. The third section<br />

shows the public methods provided by the class. We start with class Game:<br />

class Game<br />

Instance variables<br />

panel<br />

timer<br />

Methods<br />

mouseMoved<br />

mouseClicked<br />

actionPer<strong>for</strong>med<br />

Next we consider the defender object. It has a position within the panel and a size.<br />

In response to a mouse movement, it moves. It can be displayed. There<strong>for</strong>e its class<br />

diagram is:<br />

class Defender<br />

Instance variables<br />

x<br />

y<br />

height<br />

width<br />

Methods<br />

move<br />

display<br />

getX<br />

getY<br />

getHeight<br />

getWidth

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

Saved successfully!

Ooh no, something went wrong!