Professional Documents
Culture Documents
Unit 3.3 Cohesion and Coupling Week05a
Unit 3.3 Cohesion and Coupling Week05a
Size-based metric
Uses number of operators and operands in a
piece of software
n1 is the number of unique operators
n2 is the number of unique operands
N1 is the total number of occurrences of operators
N2 is the total number of occurrences of operands
Halstead derives various entities
Size of Vocabulary: n = n1+n2
Program Length: N = N1+N2
Program Volume: V = Nlog2n
Visualized as the number of bits it would take to encode the
program being measured
Halstead metrics really only measures the lexical complexity, rather than structural
complexity of source
CSE3308 - Software code.
Engineering: Analysis and Design, 2005 Lecture 5A.2
Halsteads Software Science
Assumptions
complete algorithm specification exists
programmer works alone
programmer knows what to do
Based on
N = # of unique operators
n = # of unique operands
Effort
E = N2 * log2 (n) / 4
To compute N
N = k * Ss
k = average # operators per LOC
k is language specific
To compute n
N = n * log2 (n / 2)
procedure 1
x 7
sort() 1 n 2
var 2 i 6
: 3 j 5
array 1 save 3
; 6 2 1
integer 2 1 1
, 2 n2=7 N2=25
beginend 2
for..do 2
Size of vocabulary: 21
ifthen 1
Program length: 60
Program volume: 264
:= 5
Program level: 0.04
< 1
Programming effort: 6000
[] 6
Estimated time: 333 seconds
n1=14 N1=35
Structured Design
Lecture Outline
Get
A Calling Module Customer
Details
Find
B Called Module Customer
Name
Showing Data and Information
Need to show the movement of data and the
movement of information about data (flags)
Get
Customer Flag going from caller to called
Details
Data going from caller to called
Customer
Customer
Name
Account
Flag going from called to caller
Number
Account
Number is OK
Find Data going from called to caller
Customer
Name
Difference between Data and Flags
GET TOTAL
PUT
PAYMENT FOR PUT FINAL
CUSTOMER
ONE TOTAL
TOTAL
CUSTOMER
Field
Coupling
Cohesion
Data Coupling
Good Coupling
Stamp Coupling
Control Coupling
Common Coupling
Bad Coupling
Content Coupling
Hybrid Coupling
Data Coupling
Two modules are data
coupled if they communicate
via parameters, each Assess
parameter being an House
elementary piece of data Affordability
Data coupling is necessary in Term
a program and is harmless if
kept to a minimum Interest rate Repayment
rate
Avoid tramp data that moves Sum borrowed
around the structure chart
aimlessly it creates Calculate
unnecessary and Mortgage
unpredictable dependencies, Repayment
making maintenance harder.
Tramp Data
U p d a te
C u s to m e r
M a s t e r F i le
Example
T r a n s a c t io n
V a lid
Look at the
datacouple G e t V a li d I n p u t U p d a te M a s te r
P u t C u s to m e r
Master Record M a s te r
Where is it read?
Where is it
actually needed?
How would you
change the G e t In p u t
V a li d a t e
C u s to m e r
structure chart to T r a n s a c ti o n
fix this problem?
G e t C u s to m e r G e t C u s to m e r
T r a n s a c tio n M a s te r
Stamp Coupling
Play Generate
Chess Customer
Rental Bill
Customer
Move Rental Customer
New Record Basic Rental
Gasoline
Chess Chess Rental Record
Board Board Charge
Charge
Calculate
Calculate
Make Basic
Gasoline
Move Rental
Charge
Charge
Bundling
Number of items
Price per item
Total cost Purchase data Total cost
Sales tax
Discount type
Calculate Calculate
Total Total
Purchase Purchase
Cost Cost
Control Coupling
Control coupling is when one Match
module passes to another a Customer
piece of information intended to Records
control the internal logic of the
Master
other What Record
to do
Generally not a good thing! flag Transaction
Record
Poor partitioning
Inversion of authority System
However flags which are I/O
descriptive can be fine Control
Account Number is invalid
End of file has been reached
Summary of Acceptable Coupling
Matnum Account
Miscellaneous
Functions
Impact of
cohesion
types
Consequences of Cohesion types
Cohesion Coupling Cleaness of Modifiability Understanda Effect on
Level Implementation bility maintenance
Functional Good Good Good Good Good