Lecture #11: Modularization

Reading: none
Handouts: Coupling and Cohesion
  1. Greetings and felicitations
  2. Interface
  3. Modularity: how do you break things up?

Coupling and Cohesion

This handout presents the definitions of coupling and cohesion.

Levels of Coupling

levelnamewhat it is
best5.DataParameter lists.
4.Stamp"Named common," that is, public variables shared only by those procedures that need to use them.
3.ControlFlags passed between procedures to indicate what sections of code they should execute (what functions they should perform).
2.CommonAll procedures access all public variables.
worst1.ContentProcedures modify each others' internal variables or code.
(Assembly language).
Nowadays, a combination of Data Coupling and Stamp Coupling is considered the best solution to medium-sized programming problems: Stamp Coupling is used to create shared data structures for abstract data types, and Data Coupling for everything else.

In some rare instances, Stamp Coupling may be used in place of Data Coupling when efficiency problems make parameter passing too slow or large. This is, however, a rather unsatisfactory state of affairs.

Levels of Cohesion

levelnamewhat it is
best6.Functional A procedure that accomplishes one clear function. Examples: a quicksort, a square root routine, a Roman-numeral evaluator.
Informational A group of procedures that work on the same data structure. Example: a module that implements an abstract data type.
5.Communicational A series of operations as in procedural cohesion, but applied to the same data. Example: a procedure that reads the input stream and sorts it.
4.Procedural A series of operations that have something to do with each other, in terms of the overall problem being solved. Example: a procedure that reads the input stream, breaks it intoRoman numerals, and sorts the roman numerals.
3.Temporal A series of operations related in time (only). Common examples: a procedure that initializes all data structures used in a program, one that opens all files, etc. These operations typically have rather little to do with each other, but have strong connections with other parts of the program. (For example, a file must be opened here before it can be used in other parts of the program.)
2.Logical A set of related operations, where the caller chooses which to invoke. Example: edit(op, string1, string2) where op == 1 means replace, op == 2 means delete, and so forth. Historically this has sometimes been the poor man's form of Informational Cohesion but is no longer necessary.
worst1.Coincidental No particular relation among operations. Common example: a large program arbitrarily hacked into "modular" sections.

You can also see this document as a RTF document, a Postscript document, or a plain ASCII text document.
Send email to cs40@csif.cs.ucdavis.edu.

Department of Computer Science
University of California at Davis
Davis, CA 95616-8562



Page last modified on 11/26/97