You are on page 1of 25

MAHARANA PRATAP GROUP OF INSTITUTIONS

KOTHI MANDHANA, KANPUR


(Approved by AICTE, New Delhi and Affiliated to Dr. AKTU, Lucknow)

Digital Notes
[Department of Computer Applications]
Subject Name : Software Engineering
Subject Code : KCA-302
Course : MCA
Branch : MCA
Semester : III
Prepared by : Mr. Yogendra Singh

Reference No./MCA/Yogendra Singh/KCA-302/3/2

Page 1 of 25
UNIT-III: Software Design

Basic Concepts in Software Design

Software design is a process to transform user requirements into some suitable form, which helps
the programmer in software coding and implementation.

For assessing user requirements, an SRS (Software Requirement Specification) document is


created whereas for coding and implementation, there is a need of more specific and detailed
requirements in software terms. The output of this process can directly be used into
implementation in programming languages.

Software design is the first step in SDLC (Software Design Life Cycle), which moves the
concentration from problem domain to solution domain. It tries to specify how to fulfill the
requirements mentioned in SRS.

Software Design Levels:


Software design yields three levels of results:

1. Architectural Design - The architectural design is the highest abstract version of the
system. It identifies the software as a system with many components interacting with
each other. At this level, the designers get the idea of proposed solution domain.

2. High-level Design- The high-level design breaks the ‘single entity-multiple component’
concept of architectural design into less-abstracted view of sub-systems and modules and
depicts their interaction with each other. High-level design focuses on how the system
along with all of its components can be implemented in forms of modules. It recognizes
modular structure of each sub-system and their relation and interaction among each other.

3. Detailed Design- Detailed design deals with the implementation part of what is seen as a
system and its sub-systems in the previous two designs. It is more detailed towards
modules and their implementations. It defines logical structure of each module and their
interfaces to communicate with other modules.

Page 2 of 25
Objectives of Software Design
Following are the purposes of Software design:
1. Correctness:Software design should be correct as per requirement.
2. Completeness:The design should have all components like data structures, modules, and
external interfaces, etc.
3. Efficiency:Resources should be used efficiently by the program.
4. Flexibility:Able to modify on changing needs.
5. Consistency:There should not be any inconsistency in the design.
6. Maintainability: The design should be so simple so that it can be easily maintainable by
other designers.

Modularization:
Modularization is a technique to divide a software system into multiple independent modules,
where each module works independently. These modules may work as basic constructs for the
entire software.

Overview of Modularization

Advantages of modularization:
 It makes it easy to understand the system.
 Program can be divided based on functional aspects
 Components with high cohesion can were-used again
 Desired from security aspect

Page 3 of 25
Structure Chart Definition
Structure chart (SC) is a software design tool that represents the breakdown of an entire system
into minor manageable modules using hierarchical approach.

Overview of Structure Chart

Introduction to Flowchart
A flowchart is a diagrammatic representation of an algorithm. Flowcharts depict a process or an
algorithm. The flowchart illustrates each and every step in the algorithm in the form of boxes.
The boxes would be of different shapes and each shape would have a meaning. The boxes in the
flowchart get connected with another box through arrows. The solution to a problem can be
elucidated by using the flowcharts.

Example of a flowchart
A simple flow chart to find the smaller of two numbers is depicted below.

Page 4 of 25
Advantages of flowchart

 Communicating the logics becomes very easier by making use of the flowcharts.
 Flowcharts play a greater role in analyzing the program which eventually saves time and
cost for the user.
 Flowcharts act as a blueprint for the programmers. The programmers write the code
easily by following the flowchart .

Page 5 of 25
Define coupling & cohesion?

Ans: Coupling:
 Coupling is the measure of the degree of interdependence between the two modules. A
module having high cohesion and low coupling is said to be functionally independent of
other modules. If two modules interchange large amounts of data, then they are highly
interdependent
 A good software will have low coupling.

Types of Coupling:
Following five coupling can occur between two modules.

Fig: Classification of Coupling

There are five levels of coupling, namely –


1) Data coupling: Two modules are data coupled, if they communicate by passing only
data.

2) Stamp coupling: The complete data structure is passed from one module to another
module.

3) Control coupling: if the modules communicate by passing control information, then they
are said to be control coupled.

Example: sort function that takes comparison function as an argument.

4) Common coupling: The modules have shared data such as global data structure.

Page 6 of 25
5) Content coupling:
 In content coupling, one module can modify the data of another module.
 This is the worst from of coupling and should be avoided.
Cohesion
 Cohesion is measure of the degree to which the elements of the module are functionally
related.
 It is the degree to which all elements directed towards performing a single task are
contained in the component.
 Cohesion refers to the strength of relationship among elements within a module.
 Cohesion represents how strongly the internal elements of a module are bound to each
other.
 A good software design will have high cohesion.

Types of cohesion:
There are seven types of cohesion, namely

Fig: Classification of Cohesion

1. Functional Cohesion: Elements of module are functionally related.

2. Sequential Cohesion – When elements of module are grouped because the output of one
element serves as input to another and so on, it is called sequential cohesion.

3. Communicational Cohesion – Two elements operate on the same input data or


contribute towards the same output.

4. Procedural cohesion - When elements of module are grouped together, which are
executed sequentially in order to perform a task, it is called procedural cohesion.

Example: update record in the database and send it to the printer.

Page 7 of 25
5. Temporal Cohesion - When elements of module are organized such that they are
processed at a similar point in time, it is called temporal cohesion.

6. Logical cohesion: A module is said to be logically cohesive, if all elements of the


module perform similar operations, e.g. error handling, data input, data output, etc.

7. Coincidental cohesion:
 The elements are not related.
 The elements have no conceptual relationship other than location in source code.

8. Difference between Cohesion and Coupling:

Cohesion Coupling

Cohesion is the concept of intra module. Coupling is the concept of inter module.

Cohesion represents the relationship within Coupling represents the relationships between
module. modules.
Increasing in cohesion is good for software. Increasing in coupling is avoided for software.

Cohesion represents the functional strength of Coupling represents the independence among
modules. modules.

Highly cohesive gives the best software. Whereas loosely coupling gives the best
software.

In cohesion, module focuses on the single In coupling, modules are connected to the other
thing. modules.

Page 8 of 25
Strategy of Design
To design a system, there are two possible approaches:
1. Top-down Approach
2. Bottom-up Approach

1. Top-down Approach: This approach starts with the identification of the main components
and then decomposing them into their more detailed sub-components.

2. Bottom-up Approach: A bottom-up approach begins with the lower details and moves
towards up the hierarchy, as shown in fig. This approach is suitable in case of an existing system.

Page 9 of 25
Function Oriented Design:

In function-oriented design, the system is comprised of many smaller sub-systems known as


functions. These functions are capable of performing significant task in the system. The system
is considered as top view of all functions.
Function oriented design inherits some properties of structured design where divide and conquer
methodology is used.
This design mechanism divides the whole system into smaller functions, which provides means
of abstraction by concealing the information and their operation. These functional modules can
share information among themselves by means of information passing and using information
available globally.

Another characteristic of functions is that when a program calls a function, the function changes
the state of the program, which sometimes is not acceptable by other modules. Function oriented
design works well where the system state does not matter and program/functions work on input
rather than on a state.
Design Process
 The whole system is seen as how data flows in the system by means of data flow diagram.

 DFD depicts how functions change the data and state of entire system.

 The entire system is logically broken down into smaller units known as functions on the
basis of their operation in the system.

 Each function is then described at large.

Object Oriented Design:

Object oriented design works around the entities and their characteristics instead of functions
involved in the software system. This design strategy focuses on entities and its characteristics.
The whole concept of software solution revolves around the engaged entities.

Let us see the important concepts of Object Oriented Design:

Page 10 of 25
 Objects - All entities involved in the solution design are known as objects. For example,
person, banks, company and customers are treated as objects. Every entity has some
attributes associated to it and has some methods to perform on the attributes.

 Classes - A class is a generalized description of an object. An object is an instance of a


class. Class defines all the attributes, which an object can have and methods, which
defines the functionality of the object.
 In the solution design, attributes are stored as variables and functionalities are defined by
means of methods or procedures.
 Encapsulation - In OOD, the attributes (data variables) and methods (operation on the
data) are bundled together is called encapsulation. Encapsulation not only bundles
important information of an object together, but also restricts access of the data and
methods from the outside world. This is called information hiding.

 Inheritance - OOD allows similar classes to stack up in hierarchical manner where the
lower or sub-classes can import, implement and re-use allowed variables and methods
from their immediate super classes. This property of OOD is known as inheritance. This
makes it easier to define specific class and to create generalized classes from specific
ones.

 Polymorphism - OOD languages provide a mechanism where methods performing


similar tasks but vary in arguments, can be assigned same name. This is called
polymorphism, which allows a single interface performing tasks for different types.
Depending upon how the function is invoked, respective portion of the code gets
executed.

Page 11 of 25
Difference between function Oriented Design and Object oriented Design:

S.No Function Oriented Design Object oriented Design


1 System is designed from a System is viewed as a collection of objects (i.e.
functional Viewpoint. entities)
2 Top-down approach Bottom-up approach
3 We decompose in function level We decompose in class level
4 DFD is used UML is used
5 Divide & Conquer approach

Design Process
Software design process can be perceived as series of well-defined steps. Though it varies
according to design approach (function oriented or object oriented, yet It may have the following
steps involved:
 A solution design is created from requirement or previous used system and/or system
sequence diagram.

 Objects are identified and grouped into classes on behalf of similarity in attribute
characteristics.

 Class hierarchy and relation among them are defined.

 Application framework is defined.

Software Design Approaches


There are two generic approaches for software designing:
1. Top down Design:
 We know that a system is composed of more than one sub-systems and it contains a
number of components. Further, these sub-systems and components may have their one
set of sub-system and components and creates hierarchical structure in the system.
 Top-down design takes the whole software system as one entity and then decomposes it
to achieve more than one sub-system or component based on some characteristics.

Page 12 of 25
 Top-down design starts with a generalized model of system and keeps on defining the
more specific part of it. When all components are composed the whole system comes into
existence.
 Top-down design is more suitable when the software solution needs to be designed from
scratch and specific details are unknown.
 System or component is then treated as a system and decomposed further. This process
keeps on running until the lowest or level of system in the top-down hierarchy is
achieved.

2. Bottom-up Design
 The bottom up design model starts with most specific and basic components. It proceeds
with composing higher level of components by using basic or lower level components. It
keeps creating higher level components until the desired system is not evolved as one
single component. With each higher level, the amount of abstraction is increased.
 Bottom-up strategy is more suitable when a system needs to be created from some
existing system, where the basic primitives can be used in the newer system.
 Both, top-down and bottom-up approaches are not practical individually. Instead, a good
combination of both is used.

Page 13 of 25
Halstead’s Software Science –

Halstead’s software science is an analytical technique to measure size, development effort, and
development cost of software products. Halstead used a few primitive program parameters to
develop the expressions for overall program length, potential minimum value, actual volume,
effort, and development time.
For a given program, let:
 n1 be the number of unique operators used in the program,
 n2 be the number of unique operands used in the program,
 N1 be the total number of operators used in the program,
 N2 be the total number of operands used in the program.

1) Size of Vocabulary (n): The Program vocabulary is the number of unique operators and
operands used in the program.
Vocabulary (n) = n1+ n2;
Where
n= vocabulary of a program
n1= vocabulary of a unique operators
n2= vocabulary of a unique operands

2) Length of Program (N): The length of a program is total usage of operators and
operands in the program.

Length (N) = N1+ N2;


Where
N= program length
N1= total occurrences of operators
N2= total occurrences of operands

3) Program Volume(V)
Volume (V) = Nlog2 n

4) Program Difficulty(D)
D= (n1 / 2) * (N2 / n2)

5) Effort and Time


E=D*V
T=E/18 sec.

Page 14 of 25
6) Estimated Length(N^)
N^ = n1 log2 n1 * n2 log n2

Guideline for calculating operands and operators:


1. All the variables and constants are considered as operands.
2. Local variables with same name, if occurring in different functions are counted as unique
operand.
3. Function calls are considered as operators.
4. The looping statements, do … while, while, for, are operators. The statements if, if …
else, are operators. The switch … case statements are considered as operators.
5. The reserve worlds, returns, default, continue, break, sizeof are all operators.
6. The brackets, commas, semicolons, are operators.
7. The unary and binary operators are considered as operators. The & is considered as
operator.
8. In arrays, array name and index are considered as operands and [ ] is considered as
operator.
9. All hash directives can be ignored.
10. Comments are not considered.
11. In Goto statement, goto is considered as operator and label as operand.

Page 15 of 25
Example:

Here N1=53 and N2=38. The program length N =N1+N2=91


i. Vocabulary of the program η = η1+ η2
=14+10
=24

Page 16 of 25
ii. Volume V=Nxlog2 η
=91x log2 24
=417 bits.
The estimated program length N of the program
=14 log214+10 log210
=14*3.81+10*3.32
=53.34+33.2=86.45

Page 17 of 25
Cyclomatic Complexity:

 Cyclomatic complexity is a software metric used to indicate the complexity of a program.


It is a quantitative measure of the number of linearly independent paths through a
program's source code. It was developed by Thomas J. McCabe, in 1976.

 Cyclomatic complexity is computed using the control-flow graph of the program.

 Thus, the McCabe’s cyclomatic complexity metric provides a practical way of


determining the maximum number of linearly independent paths in a program.

Calculating Cyclomatic Complexity:


The Cyclomatic complexity is calculated using methods:

Method 1:

Given a control flow graph G of a program, the cyclomatic complexity V (G) can be
computed as:
V (G) = E – N + 2P
Where-

 E = Total number of edges in the control flow graph


 N = Total number of nodes in the control flow graph
 P =The number of connected components. It is generally 1 (for single program)

Method 2:
An alternative way of computing the cyclomatic complexity of a program from an inspection
of its control flow graph is as follows:
V (G) = Total number of closed regions in the control flow graph + 1

Method 3:
Cyclomatic Complexity V (G) = P + 1

Here,
P = Total number of predicate nodes contained in the control flow graph

Page 18 of 25
Q 1 For the flow graph shown in fig ,

(i) Compute the McCobe’s cyclomatic complexity


(ii) Find out independent path
Solution:

(i) Cyclomate complexity, V (G) = E-N+2P

Where
 E = Total number of edges in the control flow graph
 N = Total number of nodes in the control flow graph
 P =The number of connected components

So we have E = 8, N = 7 and p=1

V (G) = E-N+2P
= 8-7+2
=3

(ii) Independent path

(i) 1, 2, 3, 5, 6, 7

(ii) 1, 2, 3, 4, 5, 6, 7

Page 19 of 25
(iii) 1, 2, 3, 4, 6, 7

Problem-01: Calculate cyclomatic complexity for the given code-


IF A = 354
THEN IF B > C
THEN A = B
ELSE A = C
END IF
END IF
PRINT A

Solution: We draw the following control flow graph for the given code-

Using the above control flow graph, the cyclomatic complexity may be calculated as-

Method-01:
Cyclomatic Complexity = Total number of closed regions in the control flow graph + 1
=2+1
=3

Method-02:
Cyclomatic Complexity = E – N + 2*P
=8–7+2
=3

Page 20 of 25
Method-03:
Cyclomatic Complexity = P + 1
=2+1
=3

Problem-02: Calculate cyclomatic complexity for the given control flow graph -

“An example flow-graph”, we can calculate the complexity in all three ways. There are four
regions in the graph (remember to count the space surrounding the graph, and not only the spaces
inside the graph). There are ten edges and eight nodes. There are three nodes from which two or
more edges leave. Using the three methods above, we get:

• Four regions give a cyclomatic complexity of 4.

• Ten edges and eight nodes give a cyclomatic complexity of 10 - 8 + 2 = 4

• Three nodes with two or more exiting edges gives a cyclomatic complexity of 3 + 1 = 4

Problem-03: Calculate cyclomatic complexity for the given code-


begin int x, y, power;
float z;
input(x, y);
if(y<0)
power = -y;
else power = y;
z=1;
while(power!=0)
{ z=z*x;
power=power-1;

Page 21 of 25
} if(y<0)
z=1/z;
output(z);
end
Solution- We draw the following control flow graph for the given code-

Using the above control flow graph, the cyclomatic complexity may be calculated as-

Method-01:
Cyclomatic Complexity
= Total number of closed regions in the control flow graph + 1
=3+1
=4

Method-02:
Cyclomatic Complexity
= E – N + 2*P
= 16 – 14 + 2
=4

Method-03:
Cyclomatic Complexity
=P+1
=3+1
=4

Page 22 of 25
Problem 04: Compute McCabe’s Cyclomatic Complexity.

Solution:
In this flow graph, Number of regions are 5, hence
the Cyclomatic complexity is = 5
OR
No of edges = 10
No of nodes (N) = 7
Hence Cyclomatic complexity = E-N+2*P
= 10-7+2 = 5

Page 23 of 25
Solution:
In this flow graph, Number of regions are 5, hence
the Cyclomatic complexity is = 5
OR
No of edges(E) = 10
No of nodes (N) = 7
P=1
Hence Cyclomatic complexity = E-N+2*P
= 8-7+2
=3

Page 24 of 25
Page 25 of 25

You might also like