Software Engineering for Students A Programming Approach
Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach
Summary Exercises 217 Writing a class means that strongly related elements of data and actions are grouped together. A class presents an interface to its users and hides information about its internal workings. It means that the user of a class need not worry about its implementation. This promotes abstraction in thinking about the structure of software. It also means that a class can be changed without any effect on the rest of the program (provided that it continues to present the same interface). Thus classes promote modularity. Extending (inheriting from) a class is another way of making use of existing components (classes). A subclass inherits the facilities of its immediate superclass and all the superclasses. Most languages support single inheritance. A class can extend the facilities of an existing class by providing one or more of: ■ additional methods ■ additional variables ■ methods that override (act instead of) methods in the superclass. Polymorphism means that similarities between objects can be exploited in the code that uses objects. This means that software is more concise and more easily adapted. Altogether encapsulation, inheritance and polymorphism mean that software is modular, concise and adaptable. It also means that greater use can be made of libraries of useful components. The programming language must explicitly support these features for OOP to be viable. Generics enable tailor-made collections to be constructed. This makes programs more concise and assists with compile-time type checking, and consequently software reliability. There are a number of approaches to garbage collection for software that uses dynamic allocation of memory. Some schemes are automatic but may create timing problems. Some schemes rely on the programmer to make explicit requests, but this can lead to subtle memory problems. • Exercises 15.1 Explain how classes, inheritance and polymorphism support software development. 15.2 Explain how classes, inheritance and polymorphism promote reusable software.
218 Chapter 15 ■ Object-oriented programming 15.3 Suppose that you were asked to design a new programming language for software engineering: ■ select and justify a mechanism for encapsulation ■ select and justify a mechanism for modularity. 15.4 Explain what the term modularity means. Assess how well the following features of programming languages contribute to modularity: ■ methods ■ classes. 15.5 Assess the generics feature. 15.6 Argue for and against pointers in a programming language. 15.7 Argue for and against automatic garbage collection. Answers to self-test questions 15.1 public void moveDown(int amount) { } y = y + amount; 15.2 public int yCoord { } get { return y; } 15.3 Methods: creditAccount, debitAccount, calculateInterest Properties: currentBalance, name 15.4 class Stack { } private Arraylist s = new Arraylist(); public void push(String item) { s.add(0, item); } public String pop() { String item = (String) s.get(0); s.remove(0); return item; }
- 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
- Page 217 and 218: 194 Chapter 14 ■ The basics In a
- Page 219 and 220: 196 Chapter 14 ■ The basics > str
- Page 221 and 222: 198 Chapter 14 ■ The basics Answe
- Page 223 and 224: CHAPTER 15 Object-oriented programm
- Page 225 and 226: 202 Chapter 15 ■ Object-oriented
- Page 227 and 228: 204 Chapter 15 ■ Object-oriented
- Page 229 and 230: 206 Chapter 15 ■ Object-oriented
- Page 231 and 232: 208 Chapter 15 ■ Object-oriented
- Page 233 and 234: 210 Chapter 15 ■ Object-oriented
- Page 235 and 236: 212 Chapter 15 ■ Object-oriented
- Page 237 and 238: 214 Chapter 15 ■ Object-oriented
- Page 239: 216 Chapter 15 ■ Object-oriented
- Page 243 and 244: 220 Chapter 15 ■ Object-oriented
- Page 245 and 246: 222 Chapter 16 ■ Programming in t
- Page 247 and 248: 224 Chapter 16 ■ Programming in t
- Page 249 and 250: 226 Chapter 16 ■ Programming in t
- Page 251 and 252: 228 Chapter 16 ■ Programming in t
- Page 253 and 254: 230 Chapter 16 ■ Programming in t
- Page 255 and 256: 232 Chapter 16 ■ Programming in t
- Page 257 and 258: 234 Chapter 16 ■ Programming in t
- Page 259 and 260: 236 Chapter 16 ■ Programming in t
- Page 261 and 262: 238 Chapter 17 ■ Software robustn
- Page 263 and 264: 240 Chapter 17 ■ Software robustn
- Page 265 and 266: 242 Chapter 17 ■ Software robustn
- Page 267 and 268: 244 Chapter 17 ■ Software robustn
- Page 269 and 270: 246 Chapter 17 ■ Software robustn
- Page 271 and 272: 248 Chapter 17 ■ Software robustn
- Page 273 and 274: 250 Chapter 17 ■ Software robustn
- Page 275 and 276: 252 Chapter 17 ■ Software robustn
- Page 277 and 278: 254 Chapter 17 ■ Software robustn
- Page 279 and 280: 256 Chapter 17 ■ Software robustn
- Page 281 and 282: 258 Chapter 17 ■ Software robustn
- Page 283 and 284: 260 Chapter 18 ■ Scripting GNU/Li
- Page 285 and 286: 262 Chapter 18 ■ Scripting In sum
- Page 288: PART D VERIFICATION
218 Chapter 15 ■ Object-oriented programming<br />
15.3 Suppose that you were asked to design a new programming language <strong>for</strong> software<br />
engineering:<br />
■ select and justify a mechanism <strong>for</strong> encapsulation<br />
■ select and justify a mechanism <strong>for</strong> modularity.<br />
15.4 Explain what the term modularity means. Assess how well the following features of<br />
programming languages contribute to modularity:<br />
■ methods<br />
■ classes.<br />
15.5 Assess the generics feature.<br />
15.6 Argue <strong>for</strong> and against pointers in a programming language.<br />
15.7 Argue <strong>for</strong> and against automatic garbage collection.<br />
Answers to self-test questions<br />
15.1 public void moveDown(int amount) {<br />
}<br />
y = y + amount;<br />
15.2 public int yCoord {<br />
}<br />
get {<br />
return y;<br />
}<br />
15.3 Methods: creditAccount, debitAccount, calculateInterest<br />
Properties: currentBalance, name<br />
15.4 class Stack {<br />
}<br />
private Arraylist s = new Arraylist();<br />
public void push(String item) {<br />
s.add(0, item);<br />
}<br />
public String pop() {<br />
String item = (String) s.get(0);<br />
s.remove(0);<br />
return item;<br />
}