5 Software Design
5 Software Design
Software Design
Review of previous
lectures
Introduction to software
engineering
Life cycle models
Requirements Analysis and
Specification:
y Requirements gathering and
analysis
y Requirements specification
Organization of this
Lecture
Brief review of previous lectures
Introduction to software design
Goodness of a design
Functional Independence
Cohesion and Coupling
Function-oriented design vs. Objectoriented design
Summary
Introduction
Design phase transforms SRS
document:
y into a form easily implementable in
programming
g
g language.
g g
some p
SRS Document
Design Activities
Design Documents
Module Structure
module structure,
control relationship among the modules
y call relationship or invocation relationship
2/10/2015
Introduction
A module consists of:
y several functions
y associated data structures.
D1 ..
D2 ..
D3 ..
F1 ..
F2 ..
F3 ..
F4 ..
F5 ..
Data
Functions
Introduction
Design activities are usually classified
into two stages:
y preliminary (or high-level) design
y detailed design.
g
Introduction
Good software designs:
y seldom arrived through a single
step procedure:
y but
b t th
through
h a series
i off steps
t
and
d
iterations, called the design
activities.
High-level design
Identify:
y modules
y control relationships among modules
y interfaces among modules.
High-level design
The outcome of high-level design:
y program structure (or software
architecture).
d2
d1
d3
d1
d4
High-level Design
Several notations are available to
represent high-level design:
y Usually a tree-like diagram called
structure chart is used.
y Other notations:
xJackson diagram or WarnierOrr diagram can also be used.
2/10/2015
Detailed design
For each module, design:
y data structure
y algorithms
O
Outcome
off detailed
d il d design:
d i
y module specification.
A fundamental question:
How to distinguish between good
and bad designs?
y Unless we know what a good
software design is:
xwe can not possibly design one.
2/10/2015
Understandability
Use consistent and meaningful names
y for various design components,
Modularity
Modularity
Modularity is a fundamental
attributes of any good design.
y Decomposition of a problem cleanly
into modules:
y Modules are almost independent of
each other
y divide and conquer principle.
y To understand
d
d why
h this
h is so,
x remember that it is very difficult to break
a bunch of sticks but very easy to break
the sticks individually.
Modularity
In technical terms, modules should
display:
y high cohesion
y low coupling.
coupling
Modularity
Neat arrangement of
modules in a hierarchy
means:
ylow fan-out
yabstraction
2/10/2015
C
Coupling
li between
b t
two
t
modules:
d l
y a measure of the degree of
interdependence or interaction
between the two modules.
Advantages of Functional
Independence
Better understandability and good
design:
Complexity of design is reduced,
Different modules easily understood
in isolation:
y modules are independent
Advantages of Functional
Independence
A functionally independent module:
y can be easily taken out and reused in
a different program.
x each module does some well-defined and
precise function
x the interfaces of a module with other
modules is simple and minimal.
Advantages of Functional
Independence
Functional independence reduces
error propagation.
y degree of interaction between
modules is low.
y an error existing in one module does
not directly affect other modules.
Functional Independence
Unfortunately, there are no ways:
y to quantitatively measure the
degree of cohesion and coupling:
y classification of different kinds of
cohesion and coupling:
x will give us some idea regarding the
degree of cohesiveness of a module.
2/10/2015
Classification of
Cohesiveness
Classification is often subjective:
y yet gives us some idea about
cohesiveness of a module.
Coincidental cohesion
The module performs a set of tasks:
y which relate to each other very
loosely, if at all.
x the module contains a random collection
of functions.
x functions have been put in the module
out of pure coincidence without any
thought or design.
Temporal cohesion
The module contains tasks that are
related by the fact:
Example:
Classification of
Cohesiveness
functional
sequential
communicational
procedural
Degree of
cohesion
temporal
logical
coincidental
Logical cohesion
All elements of the module perform
similar operations:
y e.g. error handling, data input, data
output, etc.
A example
An
l off logical
l i l cohesion:
h i
Procedural cohesion
The set of functions of the
module:
y all part of a procedure (algorithm)
y certain sequence of steps have to
be carried out in a certain order
for achieving an objective,
x e.g. the algorithm for decoding a
message.
2/10/2015
Communicational
cohesion
All functions of the module:
y reference or update the same data
structure,
Example:
Sequential cohesion
Elements of a module form
different parts of a sequence,
sort
search
display
Functional cohesion
Different elements of a module
cooperate:
functional cohesion,
Coupling
There are no ways to precisely determine
coupling between two modules:
Coupling
Coupling indicates:
y how closely two modules interact
or how interdependent they are.
y The
Th degree
d
off coupling
li between
b t
two modules depends on their
interface complexity.
Classes of coupling
data
stamp
control
common
Degree of
coupling
content
2/10/2015
Data coupling
Two modules are data coupled,
y if they communicate via a
parameter:
Control coupling
Data from one module is used
to direct
Content coupling
Content coupling exists between
two modules:
Stamp coupling
Two modules are stamp
coupled,
y if they communicate via a
composite data item
xsuch as a record in PASCAL
xor a structure in C.
Common Coupling
Two modules are common
coupled,
Neat Hierarchy
Control hierarchy represents:
y organization of modules.
y control hierarchy is also called
program structure.
2/10/2015
Neat Arrangement of
modules
Characteristics of Module
Structure
Depth:
Essentially means:
ylow fan-out
yabstraction
Width:
Fan-out:
Characteristics of Module
Structure
Characteristics of Module
Structure
Fan-in:
Visibility
Module Structure
Fan out=2
Fan out=1
Fan in=1
Fan in=2
Fan out=0
Control Abstraction
y Modules at higher layer should not be visible
to modules at lower layers
Goodness of Design
A design having modules:
y with high fan-out numbers is not a
good design:
y a module having high fan-out lacks
cohesion.
2/10/2015
Goodness of Design
A module that invokes a large
number of other modules:
y likely to implement several different
functions:
y not likely to perform a single cohesive
function.
Control Relationships
A module that controls another
module:
y said to be superordinate to it.
Conversely,
C
l a module
d l controlled
t ll d
by another module:
y said to be subordinate to it.
Bad Design
Abstraction
Lower-level modules:
y do input/output and other low-level
functions.
Upper-level modules:
y do more managerial functions.
Abstraction
The principle of abstraction
requires:
y lower-level modules do not invoke
functions of higher level modules
modules.
y Also known as layered design.
10
2/10/2015
High-level Design
High-level design maps functions
into modules such that:
y Each module has high cohesion
y Coupling among modules is as low as
possible
y Modules are organized in a neat
hierarchy
Design Approaches
Two fundamentally different
software design approaches:
y Function-oriented design
g
y Object-oriented design
High-level Design
f1
f2
f3
d2
d1
d3
d1
d4
fn
Design Approaches
These two design approaches
are radically different.
y However, are complementary
Function-Oriented Design
Example
y ccreates
eates tthe
e record
eco d for
o a new
e
member,
y assigns a unique membership
number
y prints a bill towards the membership
11
2/10/2015
Example
Function-Oriented Design
Create-library-member function
consists of the following subfunctions:
Each subfunction:
y assign-membership-number
y create-member-record
y print-bill
Function-Oriented Design
The system state is centralized:
y accessible to different functions,
y member-records:
Object-Oriented Design
Example
Object-Oriented Design
System is viewed as a collection
of objects (i.e. entities).
System state is decentralized
among the objects:
y each object manages its own
state information.
Object-Oriented Design
Objects have their own internal
data:
y defines their state.
12
2/10/2015
Object-Oriented Design
Data Abstraction
Data Structure
Data Type
In OOD:
In OOD:
yIdentify
Id tif verbs
b if you are after
ft
procedural design and nouns if
you are after object-oriented
design.
Example:
In an employee pay-roll system,
the following can be global data:
y names of the employees,
y their code numbers,
y basic salaries,
salaries etc.
etc
13
2/10/2015
Objects communicate by
message passing.
y one object may discover the state
information of another object by
interrogating it.
Fire-Alarm System:
Fire-Alarm System:
We need to develop a
computerized fire alarm system
g multi-storied building:
g
for a large
14
2/10/2015
Fire-Alarm System
Whenever a fire condition is
reported by any smoke detector:
y the fire alarm system should:
Fire-Alarm System
After a fire condition has been
successfully handled,
y tthe
e fire
ea
alarm
a
syste
system sshould
ou d let
et fire
e
fighting personnel reset the alarms.
Object-Oriented Approach:
class detector
find-neighbors
class alarm
operations:
i
create, ring-alarm,
i
l
get_location,
l
i
reset-alarm
In the object oriented program,
Fire-Alarm System
The fire alarm system should:
y flash an alarm message on the
computer console:
xfire
fi fighting
fi hti
personnell man the
th
console round the clock.
Function-Oriented
Approach:
/* Global data (system state) accessible by
various functions */
BOOL detector_status[1000];
int detector_locs[1000];
BOOL alarm-status[1000]; /* alarm activated when status set */
int alarm_locs[1000]; /* room number where alarm is located */
int neighbor-alarms[1000][10
g
[
][ ];//*each detector has at most*//
/* 10 neighboring
i hb i
alarm
l
locations
l
i
*/
The functions which operate on the system state:
interrogate_detectors();
get_detector_location();
determine_neighbor();
ring_alarm();
reset_alarm();
report_fire_location();
In the object
j
oriented program,
p g
,
15
2/10/2015
Summary
We started with an overview of:
y activities undertaken during the
software design phase.
We identified:
Summary
We characterized the features of
a good software design by
introducing the concepts of:
y fan-in,
f i fan-out,
f
t
y cohesion, coupling,
y abstraction, etc.
Summary
Summary
yenables us to approximately
determine the cohesion and
coupling existing in a design.
y function-oriented
u ct o o e ted app
approach
oac
y object-oriented approach
16
2/10/2015
Summary
We looked at the essential
philosophy behind these two
pp
approaches
y these two approaches are not
competing but complementary
approaches.
17