(c) Copyright 1998, 1999, 2000, 2001, 2002, 2004 by Daniel Berleant

 

What makes a module a good module?



First, Coupling



Coupling in Software, Cars, . . .


    Which of these have high coupling? Low coupling?  

    Two cooked strands of spaghetti with no oil

    Two cooked strands of spaghetti, coated with green, aromatic, expensive olive oil

    Two loops, one executing after the other is done

    Two loops, one nested in the other

    A car tire and the metal wheel it is on

    A car tire/wheel assembly and the engine

    A car tire and a road covered with beer bottles

    Two methods that operate on the same array of robots

    Two methods; one calls the other with no arguments

    Two classes with all public member variables and methods

    Two classses with mostly private members

    Cereal+milk+bowl --> low coupling

    A two-cracker sandwich with peanut butter

    A package of loose crackers

 

High coupling means weak module boundaries

Low coupling means strong module boundaries

One design criterion: minimize coupling

 


Cohesion in Cars, Software, Crackers . . .


Cohesion describes how well the contents of a module cohere (stick together)

"Cohesion is the degree of interaction within a module" 

        - Schach (bolding added)

Question: should a design goal be low cohesion or high cohesion?

 

 


Examples of Cohesion, High and Low


    Which of the following have high cohesion? 

         Which have low cohesion?

    A car

    A sealed box containing all the parts of a car

    A method with an integer argument N, which 

         contains error messages and 

         prints out error #N when N is passed to it

    A method with nested loops

    A method with loops; one runs, then the other runs

    A class in which every method contains 

            a call to at least one other method in the same class

    A class in which 

         no method calls any other method in that class

    A handful of uncooked spaghetti

    A pot of cooking spaghetti

     A handful of cooked spaghetti in which 

         the cook did not stir in oil after draining the water

    A handful of cooked spaghetti in which 

         the cook did stir in oil after draining the water

    A peanut butter cracker sandwich

    A cheese cracker sandwich

    Review Q: should one design for high or low cohesion?

   


Cohesion and Coupling: Summary and Cliffhanger



Varieties of Module Coupling



Varieties of Module Coupling - Some Details



"Cohesion": Peanut Butter has it and Modules Should


 


Varieties of Cohesion - Some Good, Some Bad


Coincidental cohesion (Bad!)

Logical cohesion

Temporal cohesion

Procedural cohesion

Communicational cohesion

Informational cohesion

Functional cohesion (Good!)

 

Coincidental Cohesion (bad)


Logical Cohesion (pretty bad)



Temporal Cohesion (kind of bad)



Procedural Cohesion (middling)



Communicational Cohesion (getting better)



Functional Cohesion (good!)



Information Cohesion (
good!)



Cohesion vs. Coupling: Summary