Software Engineering for Students A Programming Approach
Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach
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.
- Page 116 and 117: 7.3 Arguments in favor of goto 93 l
- Page 118 and 119: 7.4 Selecting control structures 95
- Page 120 and 121: while do if endif then else endWhil
- Page 122 and 123: • Exercises 7.1 Review the argume
- Page 124 and 125: count = 0 loop: count = count + 1 i
- Page 126 and 127: > 8.2 Case study 103 A statement th
- Page 128 and 129: start button event create defender
- Page 130 and 131: 8.3 ● Discussion Abstraction One
- Page 132 and 133: Exercises 109 skill. On the other h
- Page 134 and 135: CHAPTER 9 This chapter explains: 9.
- Page 136 and 137: 9.2 Identifying data flows 113 Noti
- Page 138 and 139: 9.3 Creation of a structure chart 1
- Page 140 and 141: SELF-TEST QUESTION 9.4 Discussion 1
- Page 142 and 143: Exercises 119 During the second sta
- Page 144 and 145: CHAPTER 10 This chapter explains:
- Page 146 and 147: In English, this reads: 10.2 A simp
- Page 148 and 149: 10.2 A simple example 125 Now comes
- Page 150 and 151: 10.4 Multiple input and output stre
- Page 152 and 153: Process header Process issue 10.4 M
- Page 154 and 155: 10.5 Structure clashes 131 As seen
- Page 156 and 157: 10.5 Structure clashes 133 Let us r
- Page 158 and 159: 10.6 Discussion 135 ■ teachable -
- Page 160 and 161: Exercises 137 2. a control block, s
- Page 162 and 163: CHAPTER 11 Object-oriented design T
- Page 164 and 165: Figure 11.1 The cyberspace invaders
- Page 168 and 169: 11.5 Class-responsibility-collabora
- Page 170 and 171: 11.7 ● Discussion Summary 147 OOD
- Page 172 and 173: 11.11 Compare and contrast the prin
- Page 174 and 175: CHAPTER 12 This chapter explains: 1
- Page 176 and 177: 12.3 Delegation 153 The concepts of
- Page 178 and 179: 12.5 Factory method 155 The followi
- Page 180 and 181: 12.8 Model, view controller (observ
- Page 182 and 183: Figure 12.4 Pipe and Filter pattern
- Page 184 and 185: Figure 12.6 Layers in a distributed
- Page 186 and 187: Answers to self-test questions 163
- Page 188 and 189: CHAPTER 13 Refactoring This chapter
- Page 190 and 191: 13.3 ● Move Method 13.6 Inline Cl
- Page 192 and 193: class Sprite Instance variables x y
- Page 194 and 195: Summary Summary 171 it is making po
- Page 196: PART C PROGRAMMING LANGUAGES
- Page 199 and 200: 176 Chapter 14 ■ The basics and a
- Page 201 and 202: 178 Chapter 14 ■ The basics > > >
- Page 203 and 204: 180 Chapter 14 ■ The basics > Ear
- Page 205 and 206: 182 Chapter 14 ■ The basics > Cas
- Page 207 and 208: 184 Chapter 14 ■ The basics > > >
- Page 209 and 210: 186 Chapter 14 ■ The basics > } }
- Page 211 and 212: 188 Chapter 14 ■ The basics Unfor
- Page 213 and 214: 190 Chapter 14 ■ The basics Ada d
- Page 215 and 216: 192 Chapter 14 ■ The basics The w
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