University of London CM 2010 Software Design and Development
Concept of module, and how we think about module complexity
Define the terms module and module complexity in terms of computer programs and systems
Identify the modules present in computer programs and systems
Analyse program code in terms of its complexity
SWEBOK: Software Engineering Body of Knowledge
Everything we know about building, maintaining, testing, quality evaluating… software.
ISO/IEC/IEEE 24765: a big vocabulary/dictionary of important terms in software engineering
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
Flexibility: change it more easily, more reusable.
Comprehensibility: understand code by chunks.
Shorter life cycle: i.e. having different people in the team working on different parts.
A module is a…
program unit that is discrete and identifiable with respect to compiling, combining with other units, and loading
Compiling: from source code to machine readable code, a module can be compiled on its own.
Combining: a module can be combined.
Loading: a module can be loaded independently.
logically separable part of a program
are the code discrete?
is it clear which piece of code is doing what?
is your function containing too many logically separable part?
set of source code files under version control that can be manipulated as one
source code management
is there a lot of files that can be imported into another repository?
collection of both data and the routines that act on it
Some definitions challenge one another, we can choose the most appropriate one depending on the context.
Difficult to understand
Multiple components, multiple interactions
Difficult to verify
Metrics to measure the above
What’s an example metric?
Example metric: Sangwan et al.’s excessive structural complexity (Link to PDF)
Look at open-source software engineering projects, how to know the complexity of the program over time. Both absolute complexity and relative, the former will be the graph below, and the latter will be, when the code is broken apart into modules, the fat (how much is going on) decreases, but the tangle (interaction between modules) increases.
What they expect:
The classic McCabe paper on module complexity (Link to PDF)
Bouwers et al.’s Criteria for the evaluation of implemented architechtures (Link to PDF)
Koziolek, Heiko’s Sustainability evaluation of software architectures: a systematic review (Link to PDF)
Which things we put into a module, and which things go into another module (i.e. function)
Define module cohesion in terms of comptuer program architechture
Define types of module cohesion and identify them in computer programs
Use programming techniques to improve module cohesion
Module cohesion is a way to reason about the contents of a module.
What we put into a module?
Have we made good decisions about what goes into a module?
According to the ISO/IEEE…
The manner and degree to which the tasks performed by a single software module are related to one another.
In software design, a measure of the strength of association of the elements within a module.
Communicational: the tasks performed by a software module use the same input data or contribute to producing the same output data
Functional: the tasks performed by a software module all contribute to the performance of a single function
Logical: the tasks performed by a software module perform logically similar functions
Procedural: the tasks performed by a software module all contribute to a given program procedure, such as an iteration or decision process
Sequential: the output of one task performed by a software module serves as input to another task performed by the module
Temporal: the tasks performed by a software module are all required at a particular phase of program execution
Coincidental: the tasks performed by a software have no functional relationship to one another
Different ways modules interacting with each other, when those interactions are desirable and when they’re not
Give a high level definition of module coupling and illustrate with an example
Analyse computer programs to identify different types of module coupling
Describe different types of module coupling and discuss which are desirable and which are not
manner and degree of interdependence between software modules
strength of the relationships between modules
measure of how closely connected two routines or modules are
in software design, a measure of the interdependence among modules in a computer program
Common environment: two modules access a common data area
It’s okay, but data could end up in unpredictable states.
Content: some or all contents of one module are included in the content of another module
Acceptable. This is a very common way of designing and writing code.
Control: one module communicates information to another module for the explicit purpose of influencing the latter module’s execution
Bad, might have some edge cases that’s acceptable.
Data/Input-Output: output from one module serves as input to another module
Hyrbid: different subsets of the range of values that a data item can assume are used for different and unrelated purposes in different modules
Bad.
Pathological: one module affects or depends upon the internal implementation of another
Common programing concepts and language techniques, connecting with the previous three weeks, with hands-on practices
Explain the connection between common programming concepts and module concepts
Using programming techniques to improve module coupling and cohesion
Use language features to improve module coupling and cohesion
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
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;
}
}
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);