Software Engineering for Students A Programming Approach
Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach
start button event create defender create alien start timer We have hidden the detail in such statements as: move all the objects 8.2 Case study 105 and we can study and check the high-level design without worrying about detail. When we are satisfied with the high-level design, we choose one of the statements and write down what it does in more detail. An obvious first candidate is: move all the objects and then: move alien move bomb move laser check boundaries display all the objects display background display defender display alien display laser display bomb At this stage we have expressed the design in terms of a number of methods. The most complex of these are check hits and check boundaries. So we now design their detail: check hits if collides(laser, alien) then endOfGame(userWins) else if collides(bomb, defender) then endOfGame(alienWins) endif endif >
106 Chapter 8 ■ Functional decomposition > > check boundaries if bomb is outside window then destroy bomb endif if laser is outside window then destroy laser endif This completes some of the detail. The next item that has some complexity is the method collides. It has two parameters, the objects to be tested for impact. It returns either true or false. It uses the x and y coordinates of the objects, together with their heights and widths. We use the notation a.x to mean the x coordinate of object a. (The joy of pseudo-code is that you can use any notation that is convenient.) collides(a, b) if a.x > b.x and a.y < b.y + b.height and a.x + a.width < b.x + b.width and a.y + a.width > b.y then return true else return false endif This illustrates how we have used the tool of abstraction to hide this complexity within a method. There is still some way to go with this particular design, but this much gives the flavor of the design and of the method. Notice how the design is refined again and again. Notice how, throughout, we can check the design without having to take account of a lot of unnecessary detail. Notice the informality of the statements used; we can simply make up new actions as necessary, but still within the discipline of the control structures – sequence, if and while, supplemented with methods. SELF-TEST QUESTION 8.1 Write method move alien assuming it is at window coordinates x and y. >
- Page 78 and 79: 5.3 Styles of human-computer interf
- Page 80 and 81: 5.5 Design principles and guideline
- Page 82 and 83: 5.5 Design principles and guideline
- Page 84 and 85: SELF-TEST QUESTION 5.2 What problem
- Page 86 and 87: 5.8 Help systems 63 Our plan is to
- Page 88 and 89: Further reading 65 5.5 Design a use
- Page 90 and 91: CHAPTER 6 Modularity This chapter e
- Page 92 and 93: 6.2 Why modularity? 69 observed fau
- Page 94 and 95: Figure 6.1 Two alternative software
- Page 96 and 97: ■ a simple program is more likely
- Page 98 and 99: 6.6 Information hiding 75 The class
- Page 100 and 101: 6.8 ● Coupling 6.8 Coupling 77 We
- Page 102 and 103: 6. Method calls with parameters tha
- Page 104 and 105: 3. Temporal cohesion 6.9 Cohesion 8
- Page 106 and 107: > } public void setY(int newY) { y
- Page 108 and 109: • Exercises 6.1 What is modularit
- Page 110 and 111: CHAPTER 7 Structured programming Th
- Page 112 and 113: 7.2 Arguments against goto 89 If we
- Page 114 and 115: ■ if-then-else ■ while-do or re
- 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 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 166 and 167: SELF-TEST QUESTION 11.1 Derive info
- 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
106 Chapter 8 ■ Functional decomposition<br />
><br />
><br />
check boundaries<br />
if bomb is outside window<br />
then<br />
destroy bomb<br />
endif<br />
if laser is outside window<br />
then<br />
destroy laser<br />
endif<br />
This completes some of the detail. The next item that has some complexity is the<br />
method collides. It has two parameters, the objects to be tested <strong>for</strong> impact. It<br />
returns either true or false. It uses the x and y coordinates of the objects,<br />
together with their heights and widths. We use the notation a.x to mean the x<br />
coordinate of object a. (The joy of pseudo-code is that you can use any notation<br />
that is convenient.)<br />
collides(a, b)<br />
if a.x > b.x<br />
and a.y < b.y + b.height<br />
and a.x + a.width < b.x + b.width<br />
and a.y + a.width > b.y<br />
then<br />
return true<br />
else<br />
return false<br />
endif<br />
This illustrates how we have used the tool of abstraction to hide this complexity<br />
within a method.<br />
There is still some way to go with this particular design, but this much gives the flavor<br />
of the design and of the method. Notice how the design is refined again and again. Notice<br />
how, throughout, we can check the design without having to take account of a lot of<br />
unnecessary detail. Notice the in<strong>for</strong>mality of the statements used; we can simply make up<br />
new actions as necessary, but still within the discipline of the control structures – sequence,<br />
if and while, supplemented with methods.<br />
SELF-TEST QUESTION<br />
8.1 Write method move alien assuming it is at window coordinates x<br />
and y.<br />
>