TAILIEUCHUNG - Software Engineering For Students: A Programming Approach Part 11

Software Engineering For Students: A Programming Approach Part 11. This fully revised version of Doug Bell's Software Engineering: A Programming Approach continues to use the successful formula of the previous editions. The author's approach is to present the main principles, techniques and tools used in software engineering, one by one, chapter by chapter. This book is a unique introduction to software engineering for all students of computer science and its related disciplines. It is also ideal for practitioners wishing to remain current with new developments in the area | 78 Chapter 6 Modularity 3. Modifying data within another component Allowing one component to alter another component s data seems rather less harmful than changing another component s code. However the objection is the same and the coupling is strong because a fault that appears in one component may be caused by another. 4. Shared or global data Shared data is data that two or more components have access to. The data is in a distinct component. Global data means a collection of data that is accessible to a large number of perhaps all components. The facility to access data in this way is present in nearly all widely used programming languages. We have already seen why this is undesirable. SELF-TEST QUESTION Give one reason why global data is undesirable. 5. A method call with a parameter that is a switch We have seen that both shared data and unusual transfers of control result in strong coupling between components. The solution is of course to use method calls with their attendant parameters. Even so it is possible to worsen the coupling by passing as a parameter not pure data but an element of control. An example is where a component is passed an indicator telling the method which action to take from among a number of available actions. This indicator is sometimes called a switch. Here is an example of a method call on a general-purpose input-output method inputOutput command device buffer length The parameter command has values 0 1 2 etc. that specify whether the operation is a read write open etc. This is undesirable simply because it is unnecessarily complicated. This method can be divided into several methods - each carrying out a single action. As an alternative to calling a single method and passing it a switch we can instead call the individual appropriate method like this read device buffer length We have eliminated a parameter from the interaction and at the same time created well-defined methods each with a specific function. This contrasts with a .