SDD

University of London CM 2010 Software Design and Development


Project maintained by ccy05327 Hosted on GitHub Pages — Theme by mattgraham

Topic 1 Module Coupling, Cohesion and Complexity

Week 1 Modules and module complexity

Concept of module, and how we think about module complexity

Learning Objectives

References

What is a module?

Why write modular software?

…a mechanism for improving the flexibility and comprehensibility of a system while allowing the shortening of its development time

Parnas, 1972

A module is a…

Some definitions challenge one another, we can choose the most appropriate one depending on the context.

What is module complexity?

What is complexity?

  1. Difficult to understand

  2. Multiple components, multiple interactions

  3. Difficult to verify

  4. Metrics to measure the above

What’s an example metric?

Readings


Week 2 Module cohesion: theory and analysis

Which things we put into a module, and which things go into another module (i.e. function)

Learning Objectives

Readings

What is module cohesion?

Module cohesion is a way to reason about the contents of a module.

According to the ISO/IEEE…

Different types of module cohesion


Week 3 Module coupling: thoery and analysis

Different ways modules interacting with each other, when those interactions are desirable and when they’re not

Learning Objectives

What is module coupling?

  1. manner and degree of interdependence between software modules

    • interdependence: two modules rely on each other to work
    • manner of interdependence: how does it rely on that module?
    • degree of interdependence: how many points of reliance are there?
  2. strength of the relationships between modules

    • how much impact do they have on each other?
  3. measure of how closely connected two routines or modules are

    • indirect impacts, or both closedly related to a module but no direct contacts
  4. in software design, a measure of the interdependence among modules in a computer program

Different types of module coupling


Week 4 Module coupling and cohesion in practice

Common programing concepts and language techniques, connecting with the previous three weeks, with hands-on practices

Learning Objectives

Reading

Scope

var x, y, z;

function addition(){
  z = x + y;
}

console.log(z); // Undefined
addition();
console.log(z); // NaN

Adding parameters to the function

var x, y, z;

function addition(p1, p2){
  return p1 + p2;
}

x = 10;
y = 12;
z = 14;

console.log(z); // 14
z = addition(x, y);
console.log(z); // 22

Function parameters

Bad example (no need for allowing the module to have access to the whole game’s state)


var game_state = {
  "lives": 3,
  "score": 125,
  "level": 4
}

function canHaveExtraLife(current_game_state){
  if (current_game_state.lives < 2 &&
      current_game_state.level > 4){
    return true;
  } else {
    return false;
  }
}


Instead:


var game_state = {
  "lives": 3,
  "score": 125,
  "level": 4
}

function canHaveExtraLife(lives, level){
  if (lives < 2 && level > 4){
    return true;
  } else {
    return false;
  }
}


Const

Example of pathological coupling.

function addition(p1, p2){
  return p1+p2;
}

function pathos(){
  addition = function(p1, p2){
    return p1*p2;
  }
}

var z;
z = addition(10, 12); // 22
pathos();
z = addition(10, 12); // 120

Adding the const to addition() to rule it

const function addition(p1, p2){
  return p1+p2;
}

function pathos(){
  addition = function(p1, p2){
    return p1*p2;
  }
}

var z;
z = addition(10, 12); // 22
pathos(); // will cause error
z = addition(10, 12);