UMBC CS 201, Fall 06
Cohesion is the degree of interrelatedness
of internal parts. All of the elements of a component are directed towards
and are essential for the same task, ("A function should do one thing, and
only one thing"). We should try to MAXIMIZE Cohesion.
Degrees of Cohesion
component's parts unrelated
logically related tasks and/or data placed in same component
performs several tasks in sequence, related only by timing
tasks grouped together to ensure mandatory ordering
functions operate on or produce the same data set.
output from one function is input to next.
every processing element is essential to single function, and
all such essential elements are contained within one component
where the degree of cohesion increases as we go down the list.
How much cohesion?
Functional cohesion should be achieved where ever possible.
Communicational and sequential cohesion represent a satisfactory
Logical, temporal, and procedural cohesion should be reserved for
application specific, non-reusable code.
Coincidental cohesion should not be used at all.
Example of Coincidental Cohesion
All of the following in one module:
Logic to produce student list
Logic to produce class grade report
Logic to check e-mail
Logic to change Unix password
Example of Logical Cohesion
Display time and date on the screen
Prompt user for user-id
Look up user-id in USER list
Prompt for password
Process course enrollment request
Else if not found:
do error processing
Example of Temporal Cohesion
Related only by the time they need to be done,
i.e. at the beginning of the program
Initialize two arrays
Initialize several variables
Seed the random number generator
Print a greeting
Example of Functional Cohesion
Each in a separate module:
Logic to Display Date
Logic to Display Time
Logic to prompt user for id
Logic to Validate User ID
Logic to Process Error Condition
Logic to process class enrollment request
Logic to ... etc.
Tuesday, 22-Aug-2006 07:14:13 EDT