Professional Documents
Culture Documents
Software Architecture Design
Software Architecture Design
Architecture
Fakhar Lodhi
Topics Covered: 016 – 020
Desirable Internal Design Characteristics
Software Design and
Architecture
Topic#016
What is good design?
What is good design?
· Is it efficient code?
· compact implementation?
· Most maintainable?
Maintainable Design
· Cost of system changes is minimal
· Readily adaptable to modify existing functionality and
enhance functionality
· Design is understandable
· Changes should be local in effect
END!
Software Design and
Architecture
Topic#017
Coupling
Coupling
· Coupling is the measure of dependency between
modules/components.
· The degree of interdependence between two
modules/components
· A dependency exists between two
modules/components if a change in one could
require a change in the other.
Inter-component relationship
Measuring Coupling
· The degree of coupling between modules is
determined by:
· The number of interfaces between modules (quantity)
· Complexity of each interface (determined by the type of
communication) (quality)
Why is high degree of coupling
bad?
· Highly coupled systems have strong interconnection
· High dependence of program units upon one another
· Difficult to test, reuse, and understand separately
END!
Software Design and
Architecture
Topic#018
Coupling – Example
Design of a simple web app
<!doctype html>
<html>
<head>
<script type="text/javascript" src="base.js">
</script>
<link rel="stylesheet" href="default.css">
</head>
<body>
<button onclick="highlight2()">Highlight </button>
<button onclick="normal2()">Normal </button>
<h1 id="title" class="NormalClass">
CSS <--> JavaScript Coupling
</h1>
</body>
</html>
.NormalClass {
color:inherit;
font-style:normal;
}
default.css
<!doctype html>
<html>
<head>
<script type="text/javascript" src="base.js">
</script>
<link rel="stylesheet" href="default.css">
</head>
<body>
<button onclick="highlight2()">Highlight </button>
<button onclick="normal2()">Normal </button>
<h1 id="title" class="NormalClass">
CSS <--> JavaScript Coupling
</h1>
</body> We want to change the style of the title in
</html>
response to user action
function highlight() {
document.getElementById("title").
style.color="red";
document.getElementById("title").
style.fontStyle="italic";
}
function normal() {
document.getElementById("title").
style.color="inherit";
document.getElementById("title").
style.fontStyle="normal";
}
Option A
JavaScript code modifies the style attribute of HTML element.
function highlight() {
document.getElementById("title").
className = "HighlightClass";
}
function normal() {
document.getElementById("title").
className = "NormalClass";
}
Option B
JavaScript code modifies the class attribute of HTML element.
.NormalClass {
color:inherit;
font-style:normal;
}
.HighlightClass {
color:red;
font-style:italic;
}
default.css
Software Design and
Architecture
Topic#018
END!
Software Design and
Architecture
Topic#019
Cohesion
Cohesion
· Cohesion refers to the degree to which the
elements inside a module belong together
· A measure of the strength of relationship between:
· the methods and data of a class and some unifying
purpose or concept served by that class
· the class’s methods and data themselves
END!
Software Design and
Architecture
Topic#020
Relationship between Coupling
and Cohesion
High Cohesion and Low Coupling -
Benefits
Highly Cohesive Modules Lowly Coupled Modules
· easier to read and · easier to read and
understand understand
· Easier to modify · Easier to modify
· Increased potential for · Increased potential for
reuse reuse
· Easier to develop and test · Easier to develop and test
Surprised?
Are they somehow related?
Low Cohesion and High Coupling High Cohesion and Low Coupling
Cohesion and Coupling
· Coupling: Inter-component relationships
· Cohesion: Intra-component relationships
END!