Wa0001.
Wa0001.
Unit 3
By
Shivani Aagarwal
Software Design
• Software Design is the process to transform the user requirements into some
suitable form, which helps the programmer in software coding and
implementation.
• During the software design phase, the design document is produced, based on the
customer requirements as documented in the SRS document. Hence the aim of
this phase is to transform the SRS document into the design document.
• The following items are designed and documented during the design phase:
• Different modules required.
• Control relationships among modules.
• Interface among different modules.
• Data structure among the different modules.
• Algorithms required to implement among the individual modules.
Software Design Concepts
• The software design concept simply means the idea or principle
behind the design. It describes how you plan to solve the problem of
designing software, the logic, or thinking behind how you will design
software.
• It allows the software engineer to create the model of the system or
software or product that is to be developed or built.
• The software design concept provides a supporting and essential
structure or model for developing the right software. There are many
concepts of software design and some of them are given below:
Software Design Concepts: Abstraction- hide
details
• Abstraction simply means to hide the details to reduce complexity and
increases efficiency or quality.
• Different levels of Abstraction are necessary and must be applied at each
stage of the design process so that any error that is present can be
removed to increase the efficiency of the software solution and to refine
the software solution.
• The solution should be described in broadways that cover a wide range of
different things at a higher level of abstraction and a more detailed
description of a solution of software should be given at the lower level of
abstraction.
Software Design Concepts: Modularity- subdivide the system
Preliminary
Architectura
or high-level
l Design
design
Detailed
design
Levels of Software Design: Architectural Design
At this level, the designers get the idea of the proposed solution
domain.
Levels of Software Design: High-level design Design
Ex- VALIDATE_PRODUCT_REC
IF TRANS_TYPE NOT = ‘0’ THEN
WRITE _ERR_REPORT
ENDIF
IF CUST_NO NOT NUMERIC THEN
WRITE_ERR_REPORT
ENDIF
IF PRODUCT_NO = BLANKS
WRITE_ERR_REPORT
ENDIF
END
Procedural Cohesion
• A procedurally cohesive module contains elements that belong to a common procedural unit.
• For example, a loop or a sequence of decision statements in a module may be combined to form a
separate module.
• Procedurally cohesive modules often occur when modular structure is determined from some form of
flowchart.
• Procedural cohesion often cuts across functional hues.
• A module with only procedural cohesion may contain only part of a complete function or parts of
several functions.
Ex- READ_STUD_REC _AND_TOTAL_STUDENT _AGES
NO_OF_REC = 0
TOTAL_AGE = 0
READ STUD_REC
DO WHILE MORE_REC_EXIST
ADD AGE TO TOTAL_AGE
ADD 1 TO NO_OF_REC
READ STUD_REC
ENDDO
END
Temporal Cohesion
• Modules that perform activities like "initialization," "clean-up," and "termination" are usually
temporally bound.
• Even though the elements in a temporally bound module are logically related, temporal
cohesion is higher than logical cohesion, because the elements are all executed together.
• This avoids the problem of passing the flag, and the code is usually simpler.
• – INITIALIZATION
OPEN TRANS_FILE
ISSUE PROMPT ‘ENTER DATE – DDMMYY’
READ TODAYS_DATE
SET TRANS_COUNT TO 0
SET REPORT_TOTAL TO 0
OPEN REPORT_FILE
END
Logical Cohesion
• The instructions are hardly related to each other at all
• The instructions are grouped together due to certain classes or activities.
• A flag that is passed from outside will determine which set of instructions is to be executed.
Ex – READ_ALL_FILES
CASE OF FILE_CODE
1: READ CUST_TRAN_REC
IF NOT EOF
INCREMENT CUST_TRAN_COUNT
ENDIF
2: READ CUST_MASTER_REC
IF NOT EOF
INCREMENT CUST_MASTER_COUNT
ENDIF
END CASE
END
Coincidental Cohesion
• The instructions have no relationship to each other at all, it is just a coincidence they fall in the
same module.
• It is the worst type of cohesion.
Ex- FILE PROCESSING
OPEN EMPLOYEE_UPDATE FILE
READ EMPLOYEE REC
PRINT_PAGE_HEADING
OPEN MASTER FILE(EMPLOYEE)
SET PAGE_COUNT TO 1
SET ERR_FLAG TO FLASE
END
Difference between Coupling and Cohesion
COHESION COUPLING
Cohesion is the concept of intra module. Coupling is the concept of inter module.
2. Input/Output: A parallelogram denotes any function of input/output type. Program instructions that
take input from input devices and display output on output devices are indicated with parallelogram in a
flowchart.
Basic Symbols used in Flowchart Designs
4. Decision Diamond symbol represents a decision point. Decision based operations such as
yes/no question or true/false are indicated by diamond in flowchart.
Basic Symbols used in Flowchart Designs
5. Connectors: Whenever flowchart becomes complex or it spreads over more than one page,
it is useful to use connectors to avoid any confusions. It is represented by a circle.
6. Flow lines: Flow lines indicate the exact sequence in which instructions are executed.
Arrows represent the direction of flow of control and relationship among different symbols of
flowchart.
Flowchart: Benefits
• Logic understanding
• Effective analysis
• Useful in coding
• Proper testing and debugging
• Appropriate documentation
Flowchart: Limitations
1. Complex
2. Costly
3. Difficult to modify
4. No update
Pseudo Code
• Pseudo code is a term which is often used in programming and algorithm-based
fields.
• It is a methodology that allows the programmer to represent the implementation of
an algorithm.
• It is the cooked-up representation of an algorithm.
• Often at times, algorithms are represented with the help of pseudo codes as they can
be interpreted by programmers no matter what their programming background or
knowledge is.
• It’s simply an implementation of an algorithm in the form of annotations and
informative text written in plain English. It has no syntax like any of the
programming language and thus can’t be compiled or interpreted by the computer.
• Advantages of Pseudocode Pseudo Code
• Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
• Acts as a bridge between the program and the algorithm or flowchart. Also works as a
rough documentation, so the program of one developer can be understood easily when a
pseudo code is written out. In industries, the approach of documentation is essential.
And that’s where a pseudo-code proves vital.
• The main goal of a pseudo code is to explain what exactly each line of a program should
do, hence making the code construction phase easier for the programmer.
Pseudo Code
Function Oriented Design
• The design process for software systems often has two levels. At the first level the
focus is on deciding which modules are needed for the system based on SRS
(Software Requirement Specification) and how the modules should be
interconnected.
• Function Oriented Design is an approach to software design where the design is
decomposed into a set of interacting units where each unit has a clearly defined
function.
• Generic Procedure: Start with a high-level description of what the software / program
does. Refine each part of the description one by one by specifying in greater details
the functionality of each part. These points lead to Top-Down Structure.
Function Oriented Design Strategies
1. Data Flow Diagram (DFD):
A data flow diagram (DFD) maps out the flow of information for any process or system. It
uses defined symbols like rectangles, circles and arrows, plus short text labels, to show
data inputs, outputs, storage points and the routes between each destination.
2. Data Dictionaries:
Data dictionaries are simply repositories to store information about all data items
defined in DFDs. At the requirement stage, data dictionaries contains data items. Data
dictionaries include Name of the item, Aliases (Other names for items), Description /
purpose, Related data items, Range of values, Data structure definition / form.
3. Structure Charts:
It is the hierarchical representation of system which partitions the system into black
boxes (functionality is known to users but inner details are unknown). Components are
read from top to bottom and left to right. When a module calls another, it views the
called module as black box, passing required parameters and receiving results.
4. Pseudo Code:
Pseudo Code is system description in short English like phrases describing the function.
Object Oriented Design
The state is distributed among the objects, and each object handles its state data.
For example, in a Library Automation Software, each library representative may be
a separate object with its data and functions to operate on these data.
The tasks defined for one purpose cannot refer or change data of other objects.
Objects have their internal data which represent their state. Similar objects create
a class. In other words, each object is a member of some class. Classes may
inherit features from the superclass.
Object Oriented Design
1. Objects: All entities involved in the solution design are known as objects. For example,
person, banks, company, and users are considered as objects. Every entity has some
attributes associated with it and has some methods to perform on the attributes.
2. Classes: A class is a generalized description of an object. An object is an instance of a
class. A class defines all the attributes, which an object can have and methods, which
represents the functionality of the object.
3. Messages: Objects communicate by message passing. Messages consist of the integrity
of the target object, the name of the requested operation, and any other action needed to
perform the function. Messages are often implemented as procedure or function calls.
4. Abstraction In object-oriented design, complexity is handled using abstraction.
Abstraction is the removal of the irrelevant and the amplification of the essentials.
5. Encapsulation: Encapsulation is also called an information hiding concept. The data and
operations are linked to a single unit. Encapsulation not only bundles essential
information of an object together but also restricts access to the data and methods from
the outside world.
Object Oriented Design
6. Inheritance: OOD allows similar classes to stack up in a hierarchical manner where the
lower or sub-classes can import, implement, and re-use allowed variables and
functions from their immediate super classes. This property of OOD is called an
inheritance. This makes it easier to define a specific class and to create generalized
classes from specific ones.
7. Polymorphism: OOD languages provide a mechanism where methods performing
similar tasks but vary in arguments, can be assigned the same name. This is known as
polymorphism, which allows a single interface is performing functions for different
types. Depending upon how the service is invoked, the respective portion of the code
gets executed.
FUNCTIONAL PROGRAMMING OBJECT ORIENTED PROGRAMMING
This programming paradigm emphasizes on the use This programming paradigm is based on object
of functions where each function performs a specific oriented concept. Classes are used where instance of
task. objects are created
Fundamental elements used are variables and
Fundamental elements used are objects and
functions.The data in the functions are
methods and the data used here are mutable data.
immutable(cannot be changed after creation).
Importance is not given to data but to functions. Importance is given to data rather than procedures.
The weighting factors are identified for all functional units and multiplied with the functional
units accordingly.
Function Point Metric Computation:
Unadjusted Function Point
• The procedure for the calculation of UFP in mathematical form is given below:
Wij : It is the entry of the ith row and jth column of the table 1
Zij : It is the count of the number of functional units of Type i that have been classified as
having the complexity corresponding to columnj .
Function Point
• Organizations that use function point methods develop a criterion for
determining whether a particular entry is Low, Average or High.
• Nonetheless, the determination of complexity is somewhat subjective.
• FP = UFP * CAF
• Where CAF is complexity adjustment factor and is equal to [0.65 + 0.01 x Fi]. The
Fi i( =1 to 14) are the degree of influence and are based on responses to
questions noted
Function Point
• Functions points may compute the following important metrics:
• Productivity = FP / persons-months
• Quality = Defects / FP
• Cost = Rupees / FP
• Documentation = Pages of documentation per FP
• These metrics are controversial and are not universally acceptable. There are standards
issued by the International Functions Point User Group (IFPUG, covering the Albrecht
method) and the United Kingdom Function Point User Group (UFPGU, covering the MK11
method). An ISO standard for function point method is also being developed.
Example
• Consider a project with the following functional units:
• Number of user inputs = 50
• Number of user outputs = 40
• Number of user enquiries = 35
• Number of user files = 06
• Number of external interfaces = 04
• Assume all complexity adjustment factors and weighting factors are average.
Compute the function points for the project.
• UFP = 50 x 4 + 40 x 5 + 35 x 4 + 6 x 10 + 4 x 7
• = 200 + 200 + 140 + 60 + 28 = 628
• CAF = (0.65 + 0.01 Fi)
• = (0.65 + 0.01 (14 x 3)) = 0.65 + 0.42 = 1.07
• FP = UFP x CAF
• = 628 x 1.07 = 672
Question
• An application has the following:
• 10 low external inputs, 12 high external outputs, 20 low internal logical files, 15
high external interface files, 12 average external inquiries, and a value of
complexity adjustment factor of 1.10.
• What are the unadjusted and adjusted function point counts ?
Solution
Halstead’s Software Metrics
• A computer program is an implementation of an algorithm considered to be a collection
of tokens which can be classified as either operators or operands. Halstead’s metrics are
included in a number of current commercial tools that count software lines of code. By
counting the tokens and determining which are operators and which are operands, the
following base measures can be collected :
n1 : Number of distinct operators.
n2: Number of distinct operands.
N1: Total number of occurrences of operators.
N2: Total number of occurrences of operands.
In addition to the above, Halstead defines the following:
n1*: Number of potential operators.
n2*: Number of potential operands.
• Halstead refers to n1* and n2* as the minimum possible number of operators and
operands for a module and a program respectively.
Halstead’s Software Metrics
• This minimum number would be embodied in the programming language itself,
in which the required operation would already exist (for example, in C language,
any program must contain at least the definition of the function main()), possibly
as a function or as a procedure: n1* = 2, since at least 2 operators must appear
for any function or procedure : 1 for the name of the function and 1 to serve as
an assignment or grouping symbol, and n2* represents the number of
parameters, without repetition, which would need to be passed on to the
function or the procedure.
Halstead’s Metrics
• Halstead's metrics are all defined based on its set of base quantities (n1, n2, N1, N2, n1* and n2*)
.
• The length (N) of a program P is :
• N = N1 + N2
• The vocabulary (n) of a program P is :
• n = n1 + n2
• The volume (V) of a program P is defined as :
• V = N * log2n
Halstead’s Metrics
• Difficulty level (D) = ( n1 / 2 ) * ( N2 / n2 )
• Program level (L) = 1/D
• Effort to implement (E) = V * D
Halstead’s Software Metrics
• Comments are not considered.
• The identifier and function declarations are not considered
• All the variables and constants are considered operands.
• Global variables used in different modules of the same program are counted as multiple
occurrences of the same variable.
• Local variables with the same name in different functions are counted as unique
operands.
• Functions calls are considered as operators.
• All looping statements e.g., do {…} while ( ), while ( ) {…}, for ( ) {…}, all control statements
e.g., if ( ) {…}, if ( ) {…} else {…}, etc. are considered as operators.
• In control construct switch ( ) {case:…}, switch as well as all the case statements are
considered as operators.
• The reserve words like return, default, continue, break, sizeof, etc., are considered as
Halstead’s Software Metrics
• All the brackets, commas, and terminators are considered as operators.
• GOTO is counted as an operator and the label is counted as an operand.
• The unary and binary occurrence of “+” and “-” are dealt separately. Similarly “*”
(multiplication operator) are dealt separately.
• In the array variables such as “array-name [index]” “array-name” and “index” are
considered as operands and [ ] is considered as operator.
• In the structure variables such as “struct-name, member-name” or “struct-name ->
member-name”, struct-name, member-name are taken as operands and ‘.’, ‘->’ are
taken as operators. Some names of member elements in different structure
variables are counted as unique operands.
• All the hash directive are ignored.
S.No. Operator Frequency Operand Frequency
1 main 1 a 3
2 () 4 b 3
3 int 1 c 3
4 {} 1 avg 3
5 , 7 “%d%d%d” 1
6 ; 4 3 1
7 scanf 1 “avg=%d” 1
8 printf 1
9 = 1
10 + 2
11 / 1
12 & 3
total 27 15
Halstead’s Software Metrics
n1 : Number of distinct operators =12
n2: Number of distinct operands =7
N1: Total number of occurrences of operators =27
N2: Total number of occurrences of operands=15
• The length (N) of a program P is :
•N = N1 + N2=27+15=42
• The vocabulary (n) of a program P is :
•n = n1 + n2=12+7=19
• The volume (V) of a program P is defined as :
•V = N * log n=42*4.25 =178.5
2
Halstead’s Software Metrics
• Difficulty level (D) = ( n1 / 2 ) * ( N2 / n2 ) = (12/2)*(15/7)=12.85
• Program level (L) = 1/D=1/12.85=.077
• Effort to implement (E) = V * D =178.5*12.85=2293.75
int BinSearch (char *item, char *table[], int n)
{
int bot = 0;
int top = n - 1;
int mid, cmp;
while (bot <= top) {
mid = (bot + top) / 2;
if (table[mid] == item)
return mid;
else if (compare(table[mid], item) < 0)
top = mid - 1;
else
bot = mid + 1;}return -1; // not found}
operator occurrences operands occurrences
int 5 item 3
char* 2 table 2
BinSearch() 1 n 2
, 2 bot 4
[] 3 0 2
= 5 top 4
; 8 1 3
- 2 mid 6
while() 1 cmp 1
<= 1 -1 1
{} 1
+ 2
() 4
/ 1
if() elseif else 1
return 2
compare() 1
< 1
n1:18 N1:43 n2:10 N2:28
Measure N (Length of a program) : N = N1 + N2.
= 43 + 28
= 71
Cyclomatic Complexity
= Total number of closed regions in the control flow
graph + 1
=2+1
=3
Method-02:
Cyclomatic Complexity
=E–N+2
=8–7+2
=3
Consider a software project with the following functional units:
User input = 35, User output = 15, User Enquiries = 10, User Files = 6, External Interfaces = 7.
Assume complexity adjustment factors are essential and weighting factors are average. Calculate the functional
point for the project.
Consider a software project with the following functional units:
User input = 55, User output = 35, User Enquiries = 40, User Files = 8, External Interfaces = 5.
Assume complexity adjustment factors are significantly complex and weighting factors are high. Calculate the
functional point for the project.