1
Software Design
Lecture : 9
2
Software Design Components
Ø
Principle
Ø
Criteria (this lecture)
Ø
Techniques
3
4
Range of Coupling
High Coupling
Content
Common
Control
Stamp
Loose
Data
Uncoupled
Low
Common Coupling – High
Coupling
Definition: Two components share data
§
Global data structures
§
Common blocks
Usually a poor design choice because
Example1
ü
Process control component maintains current data
about state of operation. Gets data from multiple
sources. Supplies data to multiple sink.
ü
Each source process writes directly to global data
store. Each sink process reads directly from global
data store.
8
Diagrammatic Representation
Shared Data Store
Source 1
Variable a
Source 2
Source 3
Sink
Read directly
from Variable a
Write directly to
Variable a
Example2
Process control component maintains current data about state
of operation. Gets data from multiple sources. Supplies data
to multiple sinks.
Each source process writes directly to global data store.
Each sink process reads directly from global data store.
Improvement
Data manager component is responsible for data in data
store. Processes send data to and request data from data
10
Diagrammatic Representation
Data Manager
Source 1
Variable a
Source 2
Source 3
Sink
Places request to
read
Places request to
write
11
Control Coupling – Moderate
Coupling
•
Definition: One module controls the internal logic of the
the other one through parameters
Ø
May be either good or bad, depending on situation.
ü Bad when component must be aware of internal
structure and logic of another module
ü Good if parameters allow factoring and reuse of
12
Example of Control Coupling
Ø
Two modules
exhibit control
Unsorted List
coupling if one
(``module A'')
passes to the other
(``module B'') a
Sort the list
Stamp Coupling
Ø
Definition:
Stamp coupling is when modules share a composite
data structure and use only a part of it, possibly a
different part (e.g., passing a whole record to a
function that only needs one field of it).
Example1
Customer billing system
The print routine of the customer billing accepts a
customer data structure (cid, cname, address, phone no,
email address, NIC, cell no, passport no) as an
argument, parses it, and prints the name, address, and
billing amount.
Example2
Customer Billing System
The print routine of the customer billing accepts a
customer data structure as an argument, parses it, and
prints the name, address, and billing information.
Improvement
The print routine takes the customer name, address,
16
DATA COUPLING – Lowest level of
coupling
Ø
Data coupling occurs between two modules
when data are passed by parameters using a
simple argument list and every item in the list is
used.
17
Example
18
Cohesion
ü
A measure of the closeness of the relationships
between elements of a component or "module" of
a system.
ü
High cohesion is desirable because:
§
simplifies correction, change and extension
§
reduces testing
Range of Cohesion
High Cohesion
Functional
Informational
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
Low
Coincidental Cohesion – Lowest
Cohesion
ü
Definition: Parts of the component are only
related by their location in source code
ü
A coincidentally cohesive module is one whose
activities have no meaningful relationship to one
another.
Example – Module with multiple
argument
i.
Print next line
ii.
Reverse string of characters in second argument
iii.
Add 7 to 5th argument
iv.
Convert 4th argument to float
All the above functions have no
Logical Cohesion
Ø
Definition: Elements of component are related logically
and not functionally.
Ø
Several logically related elements are in the same
component and one of the elements is selected by the
client component.
Example I/O Operation
ü
A component reads inputs from tape, disk, and network.
All the code for these functions are in the same
component.
ü
Operations are related, but the functions are
significantly different.
24
TEMPORAL COHESION
Ø
A temporally cohesive module is one which performs
several activities that are related in time.
Ø
Temporally cohesive modules typically consist of partial
activities whose only relationship to one another is that
Example
ü
One of the most common examples of a temporally
cohesive module is an initialization routine that
initializes data used by many modules throughout a
system.