Software Engineering for Students A Programming Approach
Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach
■ a simple program is more likely to be reliable ■ it is quicker to modify a simple program. 6.5 Global data is harmful 73 If we look at the world of design engineering, a good engineer insists on maintaining a complete understanding and control over every aspect of the project. The more difficult the project the more firmly the insistence on simplicity – without it no one can understand what is going on. Software designers and programmers have frequently been accused of exhibiting the exact opposite characteristic: they deliberately avoid simple solutions and gain satisfaction from the complexities of their designs. Perhaps programmers should try to emulate the approach of traditional engineers. Many software designers and programmers today strive to make their software as clear and simple as possible. A programmer finishes a program and is satisfied that it both works correctly and is clearly written. But how do we know that it is clear? Is a shorter program necessarily simpler than a longer one (that achieves the same end), or is a heavily nested program simpler than an equivalent program without nesting? People tend to hold strong opinions on questions like these; hard evidence and objective argument are rare. Arguably, what we perceive as clarity or complexity is an issue for psychology. It is concerned with how the brain works. We cannot establish a measure of complexity – for example, the number of statements in a program – without investigating how such a measure corresponds with programmers’ perceptions and experiences. 6.5 ● Global data is harmful Just as the infamous goto statement was discredited in the 1960s, so later ideas of software engineering came to regard global data as harmful. Before we discuss the arguments, let us define some terms. By global data we mean data that can be widely used throughout a piece of software and is accessible to a number of components in the system. By the term local data, we mean data that can only be used within a specific component; access is closely controlled. For any particular piece of software, the designer has the choice of making data global or local. If the decision is made to use local data, data can, of course, be shared by passing it around the program as parameters. Here is the argument against global data. Suppose that three components named A, B and C access some global data as shown in Figure 6.2. Suppose that we have to study component A in order, say, to make a change to it. Suppose that components A and B both access a piece of global data named X. Then, in order to understand A we have to understand the role of X. But now, in order to understand X we have to examine B. So we end up having to study a second component (B) when we only wanted to understand one. But the story gets worse. Suppose that components B and C share data. Then fully to understand B we have to understand C. Therefore, in order to understand component A, we have to understand not only component B but also component C. We see that in order to comprehend any component that uses global data we have to understand all the components that use it.
74 Chapter 6 ■ Modularity Figure 6.2 Global data In general, local data is preferable because: ■ it is easier to study an individual component because it is clear what data the component is using ■ it is easier to remove a component to use in a new program, because it is a selfcontained package. ■ the global data (if any) is easier to read and understand, because it has been reduced in size. So, in general, the amount of global data should be minimized (or preferably abolished) and the local data maximized. Nowadays most programming languages provide good support for local data and some do not allow global data at all. Most modern programming languages provide a facility to group methods and data into a component (called variously a component, class or package). Within such a component, the methods access the shared data, which is therefore global. But this data is only global within the component. 6.6 ● Information hiding A B C Global data X Information hiding, data hiding or encapsulation is an approach to structuring software in a highly modular fashion. The idea is that for each data structure (or file structure), all of the following: ■ the structure itself ■ the statements that access the structure ■ the statements that modify the structure are part of just a single component. A piece of data encapsulated like this cannot be accessed directly. It can only be accessed via one of the methods associated with the data. Such a collection of data and methods is called an abstract data type, or (in objectoriented programming) a class or an object.
- Page 46 and 47: ■ documentation ■ maintenance
- Page 48 and 49: 2.2 The tasks 25 An important examp
- Page 50 and 51: 2.4 Methodology 27 reality. Like an
- Page 52 and 53: ■ error free ■ fault ■ tested
- Page 54 and 55: 3.2 ● Technical feasibility 3.3 C
- Page 56 and 57: 3.5 Case study 33 The hardware cost
- Page 58 and 59: Answers to self-test questions 3.1
- Page 60 and 61: 4.2 The concept of a requirement 37
- Page 62 and 63: 4.3 The qualities of a specificatio
- Page 64 and 65: 4.5 The requirements specification
- Page 66 and 67: 4.6 The structure of a specificatio
- Page 68 and 69: 4.7 ● Use cases 4.7 Use cases 45
- Page 70 and 71: Summary The ideal characteristics o
- Page 72: Further reading 49 Further reading
- Page 76 and 77: CHAPTER 5 This chapter explains: 5.
- 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 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 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:
74 Chapter 6 ■ Modularity<br />
Figure 6.2 Global data<br />
In general, local data is preferable because:<br />
■ it is easier to study an individual component because it is clear what data the component<br />
is using<br />
■ it is easier to remove a component to use in a new program, because it is a selfcontained<br />
package.<br />
■ the global data (if any) is easier to read and understand, because it has been reduced<br />
in size.<br />
So, in general, the amount of global data should be minimized (or preferably abolished)<br />
and the local data maximized. Nowadays most programming languages provide<br />
good support <strong>for</strong> local data and some do not allow global data at all.<br />
Most modern programming languages provide a facility to group methods and data<br />
into a component (called variously a component, class or package). Within such a component,<br />
the methods access the shared data, which is there<strong>for</strong>e global. But this data is<br />
only global within the component.<br />
6.6 ● In<strong>for</strong>mation hiding<br />
A B C<br />
Global data<br />
X<br />
In<strong>for</strong>mation hiding, data hiding or encapsulation is an approach to structuring software<br />
in a highly modular fashion. The idea is that <strong>for</strong> each data structure (or file structure),<br />
all of the following:<br />
■ the structure itself<br />
■ the statements that access the structure<br />
■ the statements that modify the structure<br />
are part of just a single component. A piece of data encapsulated like this cannot be<br />
accessed directly. It can only be accessed via one of the methods associated with the<br />
data. Such a collection of data and methods is called an abstract data type, or (in objectoriented<br />
programming) a class or an object.