Modules Flashcards
Why abstraction is an advantage
- we know what it does, we don’t worry about how it works
- makes it easier for several members of a team to work on the same project
What properties should modules have?
- High cohesion - the elements of each module should be closely related to one another
- Low coupling - should be independent as possible
What is coincidental cohesion?
A function that performs unrelated operations
What is logical cohesion?
Performs one of several operations based upon a control flag parameter. Does 1 or 5 different things based on a control parameter.
What is procedural cohesion?
performs operations in a specific order, but the operations do not share any data
What is temporal cohesion?
performs several operations which are related only because they must be performed at the same time.
- initialize an array
- initialize values in array
- prints instructions
fix: have them call seperate functions that do each operation
What is communicational cohesion?
performs operations on the same data but are not otherwise related.
- get name and phone number
- verify age and id
considered acceptable if necessary
What is Sequential cohesion
function with operations that must be performed in a specific order, with the output of one operation being the input of the next.
Example:
- Inputs the number of students
- Inputs the final exam grade for each student
- calculates the min, max and average final exam grade
- Displays the student grades
- Displays the min, max and the average grade
What is functional cohesion
idea case
performs only one operation
What is Module Cohesion?
- a .c source file which contains several function
- how the data and functions within the module are related
- should contain data and a group of functions that clearly belong together.
List the function couplings
Bad
- Content coupling - one function uses code inside another function (via goto)
- Control Coupling - one function passes a parameter to another to tell the second function what to do (logical cohesion)
Acceptable
- Common coupling - two functions use the same global data
- Stamp coupling - function passes a struct to another function (second function must use most of the data in the struct)
- Data coupling - only passes primitive data another function need <– most desirable