Design 2
Design 2
1
Coupling
• Coupling indicates:
– how closely two modules interact or how
interdependent they are.
– The degree of coupling between two modules
depends on their interface complexity.
Coupling
• There are no ways to precisely measure coupling between
two modules:
– classification of different types of coupling will help us to
approximately estimate the degree of coupling between two
modules.
• Five types of coupling can exist between any two modules.
Classes of coupling
data
stamp
control Degree of
coupling
common
content
Data coupling
• Two modules are data coupled,
– if they communicate via a parameter:
• an elementary data item,
• e.g an integer, a float, a character, etc.
– The data item should be problem related:
• not used for control purpose.
Stamp coupling
• Two modules are stamp coupled,
– if they communicate via a composite data item
• or an array or structure in C.
Control coupling
• Data from one module is used to direct
– order of instruction execution in another.
• Example of control coupling:
– a flag set in one module and tested in another
module.
Common Coupling
• Essentially means:
– low fan-out
– abstraction
Characteristics of Module Structure
• Depth:
– number of levels of control
• Width:
– overall span of control.
• Fan-out:
– a measure of the number of modules directly controlled
by given module.
Characteristics of Module Structure
• Fan-in:
– indicates how many modules directly
invoke a given module.
– High fan-in represents code reuse and is
in general encouraged.
Module Structure
Fan
out=2
Fan
out=1
Fan in=1
Fan in=2
Fan
out=0
Goodness of Design
• A design having modules:
– with high fan-out numbers
is not a good design.
– a module having high fan-out lacks cohesion.
Large Fan Out
• A module that invokes a large
number of other modules:
– likely to implement several different functions:
– not likely to perform a single cohesive function.
Control Relationships
• A module that controls another module:
• d3 d4
d1
•
•
fn
Design Approaches
• Two fundamentally different software design
approaches:
– Function-oriented design
– Object-oriented design
Design Approaches
• These two design approaches are radically different.
– However, are complementary
• rather than competing techniques.
– Each technique is applicable at
• different stages of the design process.
Function-Oriented Design
• A system is looked upon as something
– that performs a set of functions.
• In OOD:
– state information is not shared in a centralized data.
– but is distributed among the objects of the system.
Example
• In an employee pay-roll system, the following can be global
data:
– names of the employees,
– their code numbers,
– basic salaries, etc.
• In contrast, in object oriented systems:
– data is distributed among different employee objects of the
system.
Object-Oriented versus Function-Oriented Design
interrogate_detectors();
get_detector_location(); Function-Oriented
determine_neighbor();
Approach
ring_alarm();
reset_alarm();
report_fire_location();
Object-Oriented Approach:
class detector
attributes: status, location, neighbors
operations: create, sense-status, get-location, find-neighbors
class alarm
attributes: location, status
operations: create, ring-alarm, get_location, reset-alarm
– Appropriate number of instances of the class detector and alarm are created.
Object-Oriented versus Function-Oriented Design
• In a function-oriented program :
– the system state is centralized
– several functions accessing these data are defined.
• In the object oriented program,
– the state information is distributed among various sensor
and alarm objects.
Object-Oriented versus Function-Oriented Design
Faculty Name
Department Name 57