Professional Documents
Culture Documents
Coupling
CS 4311
Frank Tsui, Orland Karam, and Barbara Bernal, Essential of Software
Engineering, 3rd edition, Jones & Bartett Learning. Section 8.3.
Hans van Vliet, Software Engineering, Principles and Practice, 3rd
edition, John Wiley & Sons, 2008. (Section 12.1)
1
Outline
Cohesion
Coupling
Component independence
High cohesion
Low coupling
M2
M3
3
Cohesion
Definition
The degree to which all elements of a component are
directed towards a single task.
The degree to which all elements directed towards a
task are contained in a single component.
The degree to which all responsibilities of a single
class are related.
Internal glue with which component is constructed
All elements of component are directed toward and
essential for performing the same task.
4
Type of Cohesion
High Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
Low
5
Coincidental Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
Example
1.
2.
3.
4.
Logical Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
Example
A component reads inputs from tape, disk, and
network.
All the code for these functions are in the same
component.
Operations are related, but the functions are
significantly different.
Improvement?
Temporal Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
10
Example
11
Procedural Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
...
Write output record
Read new input record
Pad input with spaces
Return new record
...
12
Communicational Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
Fetch
13
Sequential Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
14
Functional Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
One that not only performs the task for which it was designed
but
it performs only that function and nothing else.
15
Examples of Cohesion
Function A
Function Function
B
C
Function Function
D
E
logic
Function A
Time t0
Function A
Time t0 + X
Function A
Coincidental
Logical
Parts unrelated
Similar functions
Time t0 + 2X
Temporal
Related by time
Function A
Function B
Function C
Procedural
Related by order of functions
16
Function A
Function B
Function B
Function C
Function C
Communicational
Sequential
Functional
Sequential with complete, related functions
17
18
Outline
Cohesion
Coupling
19
Coupling
No dependencies
Loosely coupled
some dependencies
Highly coupled
many dependencies
20
Coupling
21
Indications of Coupling
22
Type of Coupling
High Coupling
Loose
Low
Content
Common
Avoid
External
Control
Stamp
Data
Uncoupled
Try to achieve
23
Content Coupling
Content
Common
External
Control
Stamp
Data
Uncoupled
Question
24
Example
Part of a program handles lookup for customer.
When customer not found, component adds customer by
directly modifying the contents of the data structure
containing customer data.
Improvement?
25
Common Coupling
Content
Common
External
Control
Stamp
Data
Uncoupled
Example
Process control component maintains current data
about state of operation. Gets data from multiple
sources. Supplies data to multiple sinks. Each source
process writes directly to global data store. Each sink
process reads directly from global data store.
Improvement?
27
External Coupling
Content
Common
External
Control
Stamp
Data
Uncoupled
file
Device interface
Protocol
Data format
Improvement?
28
Control Coupling
Content
Common
External
Control
Stamp
Data
Uncoupled
29
Stamp Coupling
Content
Common
External
Control
Stamp
Data
Uncoupled
30
Example
Customer Billing System
The print routine of the customer billing accepts
customer data structure as an argument, parses it,
and prints the name, address, and billing information.
Improvement?
31
32
Data Coupling
Content
Common
External
Control
Stamp
Data
Uncoupled
CS 4311
33
Uncoupled
Content
Content
Common
Common
External
Control
Control
Stamp
Stamp
Data
Data
Uncoupled
Uncoupled
34
35
P
Q
R
S
T
36
Consequences of Coupling
(pairs, 3 minutes)
37
Consequences of Coupling
High coupling
Components
Low coupling
May
38
In Class
Groups of 2 or 3:
P1: What is the effect of cohesion on
maintenance?
P2: What is the effect of coupling on
maintenance?
39