106
Function Oriented Design and Detailed Design

Function Oriented Design and Detailed Design

Embed Size (px)

DESCRIPTION

Function Oriented Design and Detailed Design. Some Concepts. Software Design. Noun : Represents the abstract entity -design- of a system Design of an existing system Every existing system has a design Design of a system to be constructed Design is a plan for a solution Verb : - PowerPoint PPT Presentation

Citation preview

Page 1: Function Oriented Design and Detailed Design

Function Oriented Design and Detailed Design

Page 2: Function Oriented Design and Detailed Design

Some Concepts

Page 3: Function Oriented Design and Detailed Design

Software Design

Noun : Represents the abstract entity -design- of a system Design of an existing system Every existing system has a design Design of a system to be constructed Design is a plan for a solution

Verb : The process of design(ing), which results in a design Resulting design is a plan for a solution

Plan for a Solution

Page 4: Function Oriented Design and Detailed Design

Design… Design activity begins with a set of

requirements Design done before the system is

implemented Design is the intermediate language

between requirements and code Moving from problem domain to solution

domain Proceeding from abstract to more

concrete representations Result is the design that will be used for

implementing the system

Page 5: Function Oriented Design and Detailed Design

Design…

Design is a creative activity Goal: to create a plan to satisfy

requirements Perhaps the most critical activity

during system development Design determines the major

characteristics of a system Has great impact on testing and

maintenance Design document forms reference

for later phases

Page 6: Function Oriented Design and Detailed Design

Levels in Design Process Architectural design

Identifies the components needed for the system, their behavior, and relationships

We have already discussed it High Level Design

Really is the module view of the system I.e. what modules are in the system and how

they are organized Logic or Low Level Design

Components and modules are designed to satisfy their specifications

How to implement components Algorithms for implementing component are

designed

Page 7: Function Oriented Design and Detailed Design

Levels… Complete design: the architectural

design, the high level design, and Logic design of each component

Page 8: Function Oriented Design and Detailed Design

Design Methodologies

Many possibilities for design, methodologies aim to reduce search space

Provide some discipline for handling complexity

Most methodologies deal with high level design

Provide a set of rules for guiding the designer

Rules do not reduce design to a sequence of mechanical steps

Many methodologies exist Different methodologies may be useful

for different applications

Page 9: Function Oriented Design and Detailed Design

Design Objectives

Goal is to find the best possible design

Have to explore different designs Evaluation criteria are often

subjective and non quantifiable Major criteria to evaluate a design

Correctness Efficiency Maintainability Cost

Page 10: Function Oriented Design and Detailed Design

Correctness is the most fundamental Does design implement requirements? Is design feasible, given the constraints?

Efficiency Concerned with the proper use of scarce

resources - processor & memory If other factors are same, efficiency

should be maximized

Design Objectives…

Page 11: Function Oriented Design and Detailed Design

Maintainability Most important quality criteria Most affected by architectural design Should facilitate testing Should facilitate discovery and

correction of bugs Make modifying the system easier

Cost For same quality, minimize cost Design costs are quite small Should try to minimize cost in later

phases

Design Objectives…

Page 12: Function Oriented Design and Detailed Design

Design Principles

Design is a creative process How to create a design from abstract

requirements There are principles for guiding

during design Two fundamental principles in the

design process Problem partition Abstraction

Page 13: Function Oriented Design and Detailed Design

Problem Partitioning

Basic principle "divide and conquer" Divide the problem into manageably

small pieces Each piece can be solved separately Each piece can be modified separately Pieces can be related to the application

Pieces cannot be independent; they must communicate

Communication adds complexity As number of components increases,

this cost increases Stop partitioning when cost is more

than benefit

Page 14: Function Oriented Design and Detailed Design

Abstraction Necessary for partitioning Used in all engineering disciplines (all

walks of life) Abstraction of existing components

Represents components as black boxes Hides the details, provides external

behavior Useful for understanding existing systems Necessary for using systems Useful for determining design of existing

systems

Page 15: Function Oriented Design and Detailed Design

Abstraction during design process Components do not exist To decide how components interact the

designer specifies the external behavior of components

Allows concentrating on one component at a time

Permits a component to be considered without worrying about others

Allows designer to control the complexity Permits gradual transition from abstract to

concrete Necessary for solving parts separately

Abstraction…

Page 16: Function Oriented Design and Detailed Design

Functional Abstraction

Employs parameterized subprograms Specifies the functional behavior of a

module Module is treated as a input/output

function Most languages provide features to

support this e.g. functions, procedures A functional module can be specified

using pre and post conditions

Page 17: Function Oriented Design and Detailed Design

An entity in the real world provides some services to the environment it belongs

Similar is the case of data entities Certain operations are required from a data

object The internals are not of consequence Data abstraction supports this view

Data is treated as a set of pre-defined operations Only operations can be performed on the objects Internals are hidden and protected

Modern languages support data abstraction eg. CLU, Ada, C++, Modula, Java

Functional Abstraction…

Page 18: Function Oriented Design and Detailed Design

Top-Down vs Bottom-up Design

Top down design starts with the system specifications Results in some form of stepwise refinement Defines a module to implement the

specifications Specifies subordinate modules Then treats each specified module as the

problem Refinement proceeds till bottom level modules

reached At each stage a clear picture of design exists Most natural for handling complex problems Have been propagated by many Many design methodologies based on this Feasibility is not know till the end

Page 19: Function Oriented Design and Detailed Design

In bottom up we start by designing bottom modules Works with layers of abstraction Necessary if existing modules have to

be reused In bottom-up must have some idea of

the top Pure top-down or bottom-up is not

possible Often a combination is used

Top-Down vs Bottom-up Design…

Page 20: Function Oriented Design and Detailed Design

Modularity A concept closely tied to abstraction Modularity supports independence of models Modules support abstraction in software Supports hierarchical structuring of

programs Modularity enhances design clarity, eases

implementation Reduces cost of testing, debugging and

maintenance Cannot simply chop a program into modules

to get modularly Need some criteria for decomposition

Page 21: Function Oriented Design and Detailed Design

Coupling

Independent modules: if one can function completely without the presence of other

Independence between modules is desirable Modules can be modified separately Can be implemented and tested separately Programming cost decreases

In a system all modules cannot be independent

Modules must cooperate with each other More connections between modules

More dependent they are More knowledge about one module is required

to understand the other module. Coupling captures the notion of

dependence

Page 22: Function Oriented Design and Detailed Design

Coupling between modules is the strength of interconnections between modules

In general, the more we must know about module A in order to understand module B the more closely connected is A to B

"Highly coupled" modules are joined by strong interconnection

"Loosely coupled" modules have weak interconnections

Coupling…

Page 23: Function Oriented Design and Detailed Design

Uncoupled -no dependencies

Highly coupled -many dependencies

Loosely coupled -some dependencies

Coupling…

Page 24: Function Oriented Design and Detailed Design

Goal: modules as loosely coupled as possible

Where possible, have independent modules

Coupling is decided during architectural design

Cannot be reduced during implementation Coupling is inter-module concept Major factors influencing coupling

Type of connection between modules Complexity of the interface Type of information flow between modules

Coupling…

Page 25: Function Oriented Design and Detailed Design

Complexity and obscurity of interfaces increase coupling

Minimize the number of interfaces per module

Minimize the complexity of each interface Coupling is minimized if

Only defined entry of a module is used by others Information is passed exclusively through

parameters Coupling increases if

Indirect and obscure interfaces are used Internals of a module are directly used Shared variables employed for communication

Coupling…

Page 26: Function Oriented Design and Detailed Design

Coupling increases with complexity of interfaces e.g. number and complexity of parameters

Interfaces are needed to support required communication

Often more than needed is used, e.g. passing entire record when only a field is needed

Keep the interface of a module as simple as possible

Coupling…

Page 27: Function Oriented Design and Detailed Design

Coupling depends on type of information flow

Two kinds of information: data or control.

Transfer of control information Action of module depends on the

information Makes modules more difficult to

understand Transfer of data information

Module can be treated as input-output function

Coupling…

Page 28: Function Oriented Design and Detailed Design

Lowest coupling: interfaces with only data communication

Highest: hybrid interfaces (some data, some control)

Coupling Interface Type of Type ofcomplexity connections

communication

Low Simple To module DataObvious by name

High Complicated To internalControl

Obscure elements Hybrid

Coupling…

Page 29: Function Oriented Design and Detailed Design

HIGH COUPLING

LOW

LOOSE

Data coupling

Stamp coupling

Uncoupled

Control coupling

Common coupling

Content couplingOne component modifies internal data of another: Not good,

Change in one component will not affect any other component

Organize data in common data store: Better, but dependencies still exist

One component passes parameters to control another component

Pass data structure from one component to another

Only data is passed, not data structure

Coupling…

Page 30: Function Oriented Design and Detailed Design

A

B C

D EComponent B

Go to D1Component D

Go to D1

D1:

B branches into D even though D is under control of C

Content Coupling

Page 31: Function Oriented Design and Detailed Design

Global: A1A2A3

Variables: V1V2

Common data areaand variable names

Component X Component Y Component Z

V1 = V2 + A1Change VI to zero Increment VI

All three components make changes to V1. Could be a problem.

Common Coupling

Page 32: Function Oriented Design and Detailed Design

Monday

Page 33: Function Oriented Design and Detailed Design

Cohesion

Coupling characterized the inter-module bond

Reduced by minimizing relationship between elements of different modules

Another method of achieving this is by maximizing relationship between elements of same module

Cohesion considers this relationship Interested in determining how closely the

elements of a module are related to each other

In practice both are used

Page 34: Function Oriented Design and Detailed Design

Cohesion of a module represents how tightly bound are the elements of the module

Gives a handle about whether the different elements of a module belong together

High cohesion is the goal Cohesion and coupling are interrelated Greater cohesion of modules, lower

coupling between module Correlation is not perfect

Cohesion…

Page 35: Function Oriented Design and Detailed Design

Levels of Cohesion

There are many levels of cohesion. Coincidental Logical Temporal Communicational Sequential Functional

Coincidental is lowest, functional is highest

Scale is not linear Functional is considered very strong

Page 36: Function Oriented Design and Detailed Design

HIGH COHESION

LOW

Logical

Temporal

Coincidental

Procedural

Communicational

Sequential

Functional

Components whose parts are unrelated to one another

Logically related functions or data elements are placed in the same component

Functions are related by timing issues only: hard to make changes

Grouping functions in a single component just to insure the proper ordering of execution

Grouping functions in a single component just because they produce the same data set

Output from one element of component input to another element of the component

Ideal cohesion: every processing element is essential to the performance of a single function

Levels of Cohesion…

Page 37: Function Oriented Design and Detailed Design

FUNCTION D

FUNCTION E

ProceduralRelated by order of

functions

LogicalSimilar functions

FUNCTION A

FUNCTION A’

FUNCTION A”

logic

TemporalRelated by time

TIME T0

TIME T0 + X

TIME T0 + 2X

FUNCTION A

FUNCTION B

FUNCTION C

FUNCTION A

FUNCTION B

FUNCTION C

CommunicationalAccess same data

SequentialOutput of one part

is input to next

DATA

FUNCTION A

FUNCTION B

FUNCTION C

FunctionalSequential with

complete, related functions

FUNCTION A - part 1

FUNCTION A - part 2

FUNCTION A - part 3

CoincidentalParts unrelated

FUNCTION A

FUNCTIONB

FUNCTION C

Levels of Cohesion…

Page 38: Function Oriented Design and Detailed Design

Determining Cohesion Describe the purpose of a module in

a sentence Perform the following tests

1. If the sentence has to be a compound sentence, contains more than one verb, the module is probably performing more than one function. Probably has sequential or communicational cohesion.

2. If the sentence contains words relating to time, like "first", "next", "after", "start" etc., the module probably has sequential or temporal cohesion.

Page 39: Function Oriented Design and Detailed Design

3. If the predicate of the sentence does not contain a single specific object following the verb, the module is probably logically cohesive. E.g. "edit all data", while "edit source data" may have functional cohesion.

4. Words like "initialize", "clean-up" often imply temporal cohesion.

Functionally cohesive module can always be described by a simple statement

Determining Cohesion…

Page 40: Function Oriented Design and Detailed Design

E

A

B C

F

D

G

System 1

E

A

B C FD

System 2

G

Scope of control: has control on other elements

Scope of effect: controlled by other elements

No component should be in the scope of effect if it is not in the scope of control. If scope of effect is wider than scope of control, almost impossible to guarantee that a change will not destroy the system.

System 1 may be better because of this.

Scope of Control

Page 41: Function Oriented Design and Detailed Design

Summary Design is a creative activity Goal is to find the best possible design Two levels in the design process Architectural design and logic design Correctness of design is most fundamental

property Design principles

Problem partitioning Abstraction

When using functional abstraction aim for Low coupling High cohesion

Design Methodologies - a set of rules/steps to guide the designer

Page 42: Function Oriented Design and Detailed Design

Wednesday

Page 43: Function Oriented Design and Detailed Design

Structured Design Methodology

Page 44: Function Oriented Design and Detailed Design

Program Structure and Structure Charts

Every program has a structure Structure Chart - graphic representation of

structure Structure Chart represents modules and

interconnections Each module is represented by a box If A invokes B, an arrow is drawn from A to

B Arrows are labeled by data items Different types of modules in a Structure

Chart Input, output, transform and coordinate

modules A module may be a composite

Page 45: Function Oriented Design and Detailed Design

Structure Chart shows the static structure, not the logic

Different from flow charts Major decisions and loops can be shown Structure is decided during design Implementation does not change

structure Structure effects maintainability Structured Design Methodology aims to

control the structure

Program Structure and Structure Charts

Page 46: Function Oriented Design and Detailed Design

Structure Chart of a Sort Program

Page 47: Function Oriented Design and Detailed Design

Diff types of modules

Page 48: Function Oriented Design and Detailed Design

Iteration and decision

Page 49: Function Oriented Design and Detailed Design

STRUCTURED DESIGN METHODOLOGY

SDM views software as a transformation function that converts given inputs to desired outputs

The focus of Structured Design is the transformation function

Uses functional abstraction Goal of SDM: Specify functional modules

and connections Low coupling and high cohesion is the

objective

TransformationfunctionsInput Output

Page 50: Function Oriented Design and Detailed Design

Steps in Structured Design

Draw a Data Flow Diagram of the system

Identify most abstract inputs and most abstract outputs

First level factoring Factoring of input, output, transform

modules Improving the structure

Page 51: Function Oriented Design and Detailed Design

Data Flow Diagrams

Structured Design starts with a DFD to capture flow of data in the proposed system

DFD is an important representation; provides a high level view of the system

Emphasizes the flow of data through the system

Ignores procedural aspects (Purpose here is different from DFDs

used in requirements analysis, thought notation is the same)

Page 52: Function Oriented Design and Detailed Design

Drawing a Data Flow Graph

Start with identifying the inputs and outputs Work your way from inputs to outputs, or vice

versa If stuck, reverse direction Ask: "What transformations will convert the

inputs to outputs" Never try to show control logic.

If thinking about loops, if-then-else, start again Label each arrow carefully Make use of * and +, and show sufficient detail Ignore minor functions in the start For complex systems, make data flow graph

hierarchical Never settle for the 1st data flow graph

Page 53: Function Oriented Design and Detailed Design

Step 2 of Structured Design Methodology

Generally a system performs a basic function

Often cannot be performed on inputs directly

First inputs must be converted into a suitable form

Similarly for outputs - the outputs produced by main transforms need further processing

Many transforms needed for processing inputs and outputs

Goal of step 2 is to separate such transforms from the basic transform centers

Page 54: Function Oriented Design and Detailed Design

Step 2…

Most abstract inputs: data elements in data flow graph that are furthest from the actual inputs, but can still be considered as incoming

These are logical data items for the transformation

May have little similarity with actual inputs.

Often data items obtained after error checking, formatting, data validation, conversion etc.

Page 55: Function Oriented Design and Detailed Design

Step 2… Travel from physical inputs towards outputs

until data can no longer be considered incoming

Go as far as possible, without loosing the incoming nature

Similarly for most abstract outputs Represents a value judgment, but choice is

often obvious Bubbles between most abstract input (MAI)

and most abstract output (MAO): central transforms

These transforms perform the basic transformation

With MAI and MAO the central transforms can concentrate on the transformation

Page 56: Function Oriented Design and Detailed Design

Step 2…

Problem View: Each system does some i/o and some processing

In many systems the i/o processing forms the large part of the code

This approach separates the different functions subsystem primarily performing input subsystem primarily performing

transformations subsystem primarily performing output

presentation

Page 57: Function Oriented Design and Detailed Design

Example 1 – counting the number of different words in a file

Get Word List

Sort the List

Print the

count

Count the

number of

different words

InputWord list

Sorted word list Count

Data Flow Diagram

Page 58: Function Oriented Design and Detailed Design

Example 1 – counting the number of different words in a file

Page 59: Function Oriented Design and Detailed Design

Example 2 – ATM

Page 60: Function Oriented Design and Detailed Design

Wednesday

Page 61: Function Oriented Design and Detailed Design

First Level Factoring First step towards a structure chart Specify a main module For each most abstract input data item,

specify a subordinate input module The purpose of these input modules is to

deliver to main the MAI data items For each most abstract output data

element, specify an output module For each central transform, specify a

subordinate transform module Inputs and outputs of these transform

modules are specified in the DFD

Page 62: Function Oriented Design and Detailed Design

First level factoring is straight forward Main module is a coordinate module Some subordinates are responsible for

delivering the logical inputs These are passed to transform modules

to get them converted to logical outputs Output modules then consume them Divided the problem into three separate

problems Each of the three different types of

modules can be designed separately These modules are independent

First Level Factoring

Page 63: Function Oriented Design and Detailed Design

Example 1

Page 64: Function Oriented Design and Detailed Design

Example 2

Page 65: Function Oriented Design and Detailed Design

Factoring Input modules

The transform that produced the MAI data is treated as the central transform

Then repeat the process of first level factoring

Input module being factored becomes the main module

A subordinate input module is created for each data item coming in this new central transform

A subordinate module is created for the new central transform

Generally there will be no output modules

Page 66: Function Oriented Design and Detailed Design

The new input modules are factored similarly until the physical inputs are reached

Factoring of the output modules is symmetrical

Subordinates - a transform and output modules

Usually no input modules

Factoring Input modules

Page 67: Function Oriented Design and Detailed Design

Example 1

Page 68: Function Oriented Design and Detailed Design

Factoring Central Transforms

Factoring i/o modules is straight forward if the DFD is detailed

No rules for factoring the transform modules

Top-down refinement process can be used Goal: determine sub-transforms that will

together compose the transform Then repeat the process for newly found

transforms Treat the transform as a problem in its own

right Draw a data flow graph Then repeat the process of factoring Repeat this till atomic modules are reached

Page 69: Function Oriented Design and Detailed Design

Example 1

Page 70: Function Oriented Design and Detailed Design

Design Heuristics The above steps should not be followed blindly The structure obtained should be modified if

needed Low coupling, high cohesion being the goal Design heuristics used to modify the initial design Design heuristics - A set of thumb rules that are

generally useful Module Size: Indication of module complexity.

Carefully examine modules less than a few lines or greater than about 100 lines

Fan out (number of arrows going out) and fan in (number of arrows going in)

A high fan out is not desired, should not be increased beyond 5 or 6

Fan in should be maximized

Page 71: Function Oriented Design and Detailed Design

Scope of effect of a module: the modules affected by a decision inside the module

Scope of control: All subordinates of the module

Good thumb rule: For each module scope of effect should be a subset of scope of control

Ideally a decision should only effect immediate subordinates

Moving up the decision, moving the module down can be utilized to achieve this

Design Heuristics

Page 72: Function Oriented Design and Detailed Design

Transaction Analysis

The above approach is transform analysis In this data flows from input to output

through various transforms In transaction processing type situations,

many different types of processing are done depending on type

The DFD of such a system shows a bubble splitting data into many streams

In execution, one of the streams is followed

Transaction analysis is best for this

Page 73: Function Oriented Design and Detailed Design

DFD shown in figure Note the use of + signifying OR There is a transaction center, T T takes input & then performs

different transformations This can be converted to Structured

Chart as shown In smaller systems, dispatching may

be done in the transaction center itself

Transaction Analysis

Page 74: Function Oriented Design and Detailed Design

DFD for transaction analysis

Page 75: Function Oriented Design and Detailed Design

Transaction analysis…

Page 76: Function Oriented Design and Detailed Design

Summary

Goal of design phase: produce simpler & modular design

Structured design methodology is one way to create modular design

It partitions the system into input subsystems, output subsystems & transform subsystems

Idea: Many systems use a lot of code for handling inputs & outputs

Structured Design Methodology separates these concerns

Then each of the subsystems is factored using the DFD

The design is finally documented & verified before proceeding

Page 77: Function Oriented Design and Detailed Design

Chapter 8 Detailed Design

Page 78: Function Oriented Design and Detailed Design

Detailed Design

HLD does not specify module logic This is done during detailed design Process Design Logic (PDL) can also be used

for detailed design of modules PDL can be used to specify the complete

design - architectural as well as logic design The degree of detail desired is decided by

the designer One way to communicate a design: use

natural language Is imprecise and can lead to

misunderstanding

Page 79: Function Oriented Design and Detailed Design

Other extreme is to use a formal language

Such representations often have a lot of detail, necessary for implementation, but not important for communicating the

design These details are often a hindrance

to understanding

Detailed Design

Page 80: Function Oriented Design and Detailed Design

Ideally would like a language that is as precise as possible Does not need too much detail, target language independent can be easily converted in to an implementation

This is what PDL attempts to do. PDL has outer syntax of a structure

programming language Vocabulary of a natural language (English in

our case) It can be thought of as "structured english" Some automated processing can be done on

PDL

Detailed Design

Page 81: Function Oriented Design and Detailed Design

E.g.. determine the min and max of a set of numbers in a file

A design in PDL is:minmax (in file)ARRAY a

DO UNTIL end of input READ an item into a

ENDDOmax, min: = first item of a DO FOR each item in a

IF max < item THEN set max to itemIF min > item THEN set min to item

ENDDO END

Detailed Design

Page 82: Function Oriented Design and Detailed Design

The entire logic is described Few implementation details For implementation, the pseudo statements

will have to be converted into programming language statements

A design can be expressed in level of detail suitable for the problem

PDL allows a successive refinement approach Encourages use of structured language

constructs

Detailed Design

Page 83: Function Oriented Design and Detailed Design

The basic constructs of PDL if-then-else construct Like Pascal Conditions and the statements need not be

stated formally

A general CASE statement Some examples of CASE

CASE OF transaction type CASE OF operator type

The DO construct: used to indicate repetitionDO iteration criteriaone or more statementsENDDO

Page 84: Function Oriented Design and Detailed Design

The iteration criteria need not be stated formally

Examples of valid use are: DO WHILE there are characters in input

file DO UNTIL the end of file is reached DO FOR each item in the list EXCEPT

when item is zero. A variety of data structures can be

defined e.g. list, tables, scalar, records, arrays etc. All constructs should be programmable

Detailed Design

Page 85: Function Oriented Design and Detailed Design

Initialize buf to emptyDO FOREVER

DO UNTIL (#chars in buf 80 & word boundary is reached) OR (end of text is reached)

read chars in bufENDDOIF #chars > 80 THEN

remove last word from bufPRINT-WITH-FILL (buf)set buf to last word ELSEIF #chars = 80

THENprint (buf)set buf to empty

ELSE EXIT the loopENDDO

PDL Example: Format Text

Page 86: Function Oriented Design and Detailed Design

PROCEDURE PRINT-WITH-FILL (buf)Determine #words and #characters in

buf#of blanks needed = 80 - #charactersDO FOR each word in the buf

print (word)IF #printed words (#word - #of blanks needed) THEN

print (two blanks)ELSE print (single blank)

ENDDO

PDL Example: Format Text…

Page 87: Function Oriented Design and Detailed Design

PROCEDURE PRINT-WITH-FILL (buf)Determine #words and #characters in

buf#of blanks needed = 80 - #charactersDO FOR each word in the buf

print (word)IF #printed words (#word - #of blanks needed) THEN

print (two blanks)ELSE print (single blank)

ENDDO

PDL Example: Format Text…

Page 88: Function Oriented Design and Detailed Design

int count (file)FILE fileword_list w1{

READ_FROM_FILE file into w1sort (w1)count = DIFFERENT-WORDS (w1)print (count)

}

PDL Example: Count Words in File

Page 89: Function Oriented Design and Detailed Design

READ_FROM_FILE (file, w1)FILE fileword_list w1{

initialize w1 to emptyWHILE not end-of-file {

get a word from fileadd word to w1

}}

PDL Example: Count Words in File…

Page 90: Function Oriented Design and Detailed Design

int DIFFERENT_WORDS (w1)word_list w1{

word last, curint cntlast = first word in w1cnt = 1WHILE not end of list {

cur = next word from w1IF (cur <> last) {

cnt = cnt + 1last = cur

}}RETURN (cnt)

}

PDL Example: Count Words in File…

Page 91: Function Oriented Design and Detailed Design

Design Verification

Main objective: does the design implement the requirements

Analysis for performance, efficiency, etc may also be done

If formal languages used for design representation, tools can help

Design reviews remain the most common approach for verification

Page 92: Function Oriented Design and Detailed Design

Critical Design Review Checklist

Does each module in the system design exist in detailed design?

Are there analyses to demonstrate that th performance requirements can be met?

Are all the assumptions explicitly stated, and are they acceptable?

Are all relevant aspects of system design reflected in detailed design?

Have the exceptional conditions been handled? Are all the data formats consistent with the system design? Is the design structured, and does it conform to local

standards? Are the sizes of data structures estimated? Are provisions

made to guard against overflow? Is each statement specified in natural language easily coded? Are the loop termination conditions properly specified? Are the conditions in the loops OK? Are the conditions in the if statements correct? Is the nesting proper? Is the module logic too complex? Are the modules highly cohesive?

Page 93: Function Oriented Design and Detailed Design

Friday

Page 94: Function Oriented Design and Detailed Design

Metrics

Page 95: Function Oriented Design and Detailed Design

Background

Basic purpose to provide a quantitative evaluation of the design (so the final product can be better)

Size is always a metric – after design it can be more accurately estimated Number of modules and estimated size

of each is one approach Complexity is another metric of

interest – will discuss a few metrics

Page 96: Function Oriented Design and Detailed Design

Common software metrics

Source lines of code Cyclomatic complexity Function point analysis Bugs per line of code Code coverage Number of lines of customer

requirements. Number of classes and interfaces Robert Cecil Martin’s software package

metrics Cohesion Coupling

Page 97: Function Oriented Design and Detailed Design

Cyclomatic Complexity Metric

Focus on structure chart; a good SC is considered as one with each module having one caller (reduces coupling)

The more the SC deviates from a tree, the more impure it is

Graph impurity = n – e – 1n – nodes, e- edges in the graph

Impurity of 0 means tree; as this number increases, the impurity increases

Page 98: Function Oriented Design and Detailed Design

Cyclomatic Complexity…

Simple what to measure Start with 1 for a straight path through

the routine. Add 1 for each of the following keywords

or their equivalent: if, while, repeat, for, and, or.

Add 1 for each case in a switch statement.

Page 99: Function Oriented Design and Detailed Design

Cyclomatic Complexity… Example 1public void ProcessPages() {   while(nextPage=true)  {    if((lineCount<=linesPerPage) && (status != Status.Cancelled) && (morePages == true))   {    //....    }   } } In the code above, we start with 1 for the routine,

add 1 for the while loop, add 1 for the if, and add 1 for each && for a total calculated complexity of 5.

Page 100: Function Oriented Design and Detailed Design

Cyclomatic Complexity…

Example 2public int getValue(int param1) { int value = 0;   if (param1 == 0)  {    value = 4;   }   else  {    value = 0;   }   return value; } In the code above, we start with 1 for the routine, add 1 for

the if, and add 1 for the else for a total calculated complexity of 3.

Page 101: Function Oriented Design and Detailed Design

Cyclomatic Complexity…

Members that have high code complexity should be reviewed for possible refactoring.

The SEI provides the following basic risk assessment based on the value of code:

Cyclomatic Complexity Risk Evaluation1 to 10 a simple program, without very much risk11 to 20 a more complex program, moderate risk21 to 50 a complex, high risk program> 50 an un-testable program (very high risk)

Page 102: Function Oriented Design and Detailed Design

Code coverage

Function coverage - Has each function in the program been executed?

Statement coverage - Has each line of the source code been executed?

Condition coverage - Has each evaluation point (such as a true/false decision) been executed?

Path coverage - Has every possible route through a given part of the code been executed?

Entry/exit coverage - Has every possible call and return of the function been executed?

Page 103: Function Oriented Design and Detailed Design

Robert Cecil Martin’s software package metrics

Number of Classes and Interfaces: The number of concrete and abstract classes (and interfaces) in the package is an indicator of the extensibility of the package.

Afferent Couplings (Ca): The number of other packages that depend upon classes within the package is an indicator of the package's responsibility.

Efferent Couplings (Ce): The number of other packages that the classes in the package depend upon is an indicator of the package's independence.

Abstractness (A): The ratio of the number of abstract classes (and interfaces) in the analyzed package to the total number of classes in the analyzed package. The range for this metric is 0 to 1, with A=0 indicating a completely concrete package and A=1 indicating a completely abstract package.

Instability (I): The ratio of efferent coupling (Ce) to total coupling (Ce + Ca) such that I = Ce / (Ce + Ca). This metric is an indicator of the package's resilience to change. The range for this metric is 0 to 1, with I=0 indicating a completely stable package and I=1 indicating a completely instable package.

Distance from the Main Sequence (D): The perpendicular distance of a package from the idealized line A + I = 1. This metric is an indicator of the package's balance between abstractness and stability.

Package Dependency Cycles: Package dependency cycles are reported along with the hierarchical paths of packages participating in package dependency cycles.

Page 104: Function Oriented Design and Detailed Design

Stability Metrics

Stability tries to capture the impact of a change on the design

Higher the stability, the better it is Stability of a module – the number of

assumptions made by other modules about this module Depends on module interface, global data

the module uses Are known after design

Page 105: Function Oriented Design and Detailed Design

Information Flow Metrics

Complexity of a module is viewed as depending on intra-module complexity

Intra-module estimated by module size and the information flowing Size in LOC Inflow – information flowing in the module Outflow – information flowing out of the

module Design Complexity (DC)

DC = size * (inflow * outflow)2

Page 106: Function Oriented Design and Detailed Design

Information flow metrics…

(inflow * outflow) represents total combination of inputs and outputs

Its square represents interconnection between the modules

Size represents the internal complexity of the module

Product represents the total complexity