21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.8 ● Coupling<br />

6.8 Coupling 77<br />

We are familiar with the idea of one component making a method call on another, but<br />

what other types of interaction (coupling) are there between components? Which types<br />

are good and which bad?<br />

First, an important aspect of the interaction between components is its “size”.<br />

The fewer the number of elements that connect components, the better. If components<br />

share common data, it should be minimized. Few parameters should be passed<br />

between components in method calls. It has been suggested that no more than<br />

about 2–4 parameters should be used. Deceit should not be practiced by grouping<br />

together several parameters into a record and then using the record as a single<br />

parameter.<br />

What about the nature of the interaction between components? We can distinguish<br />

the following ways in which components interact. They are listed in an order that goes<br />

from strongly coupled (least desirable) to weakly coupled (most desirable):<br />

1. altering another component’s code<br />

2. branching to or calling a place other than at the normal entry point<br />

3. accessing data within another component<br />

4. shared or global data<br />

5. method call with a switch as a parameter<br />

6. method call with pure data parameters<br />

7. passing a serial data stream from one component to another.<br />

We now examine each of these in turn.<br />

1. Altering another component’s code<br />

This is a rather weird type of interaction and the only programming language that normally<br />

allows it is assembler. However, in Cobol the alter statement allows a program<br />

to essentially modify its own code. The problem with this <strong>for</strong>m of interaction is that a<br />

bug in one component, the modifying component, appears as a symptom in another,<br />

the one being modified.<br />

2. Entering at the side door<br />

In this type of interaction, one component calls or branches to another at a place other<br />

than the normal entry point of the component. Again, this is impossible in most languages,<br />

except assembler, Cobol and early versions of Basic.<br />

The objection to this type of interaction is part of the argument <strong>for</strong> structured programming.<br />

It is only by using components that have a single entry (at the start) and<br />

one exit (at the end) that we can use the power of abstraction to design and understand<br />

large programs.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!