Software Metrics and Design Principles. What is Design? Design is the process of creating a plan or blueprint to follow during actual construction Design.

Slides:



Advertisements
Similar presentations
Lecture 6: Software Design (Part I)
Advertisements

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Software Design Main issues:  decompose system into parts  many attempts to measure the results  design as product  design as process.
Structured Design. 2 Design Quality – Simplicity “There are two ways of constructing a software design: One is to make it so simple that there are obviously.
Program Slice Program slice was a concept first discussed by Mark Weiser in the early 1980’s –He especially noticed that when people debug, they trace.
Communication between modules, cohesion and coupling
Design Concepts and Principles
1 Software Design Introduction  The chapter will address the following questions:  How do you factor a program into manageable program modules that can.
Chapter 13 Design Concepts and Principles
What is Software Design?  Introduction  Software design consists of two components, modular design and packaging.  Modular design is the decomposition.
Copyright Irwin/McGraw-Hill Software Design Prepared by Kevin C. Dittman for Systems Analysis & Design Methods 4ed by J. L. Whitten & L. D. Bentley.
© Copyright 2011 John Wiley & Sons, Inc.
Software Metrics II Speaker: Jerry Gao Ph.D. San Jose State University URL: Sept., 2001.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Jump to first page 1 System Design (Finalizing Design Specifications) Chapter 3d.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
1 Complexity metrics  measure certain aspects of the software (lines of code, # of if-statements, depth of nesting, …)  use these numbers as a criterion.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
University of Toronto Department of Computer Science © 2001, Steve Easterbrook CSC444 Lec22 1 Lecture 22: Software Measurement Basics of software measurement.
1 Software Quality CIS 375 Bruce R. Maxim UM-Dearborn.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
 2004 by SEC Chapter 4 Software Design. 2  2004 by SEC Chapter 4 Software Design 4.1 Design Fundamentals 4.2 Design Method 4.3 Architecture Design
Program Design Simple Program Design Third Edition A Step-by-Step Approach 9.
Software Design and Architecture Theoretical Principles and Design Methods.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
SOFTWARE DESIGN.
1 Software Design Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13, 5 th edition and Ch. 10, 6 th edition.
SOFTWARE DESIGN Design Concepts Design is a meaningful engineering representation of something that is to be built It can be traced to a customer’s requirements.
Sommerville, Mejia-Alvarez, 2009Software Engineering, Slide 1 Software Design u Deriving a solution which satisfies software requirements.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 23 Instructor Paulo Alencar.
Software Design Deriving a solution which satisfies software requirements.
1 Software Design Overview Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13.
Software Metrics (Part II). Product Metrics  Product metrics are generally concerned with the structure of the source code (example LOC).  Product metrics.
Software Quality Metrics
Concepts of Software Quality Yonglei Tao 1. Software Quality Attributes  Reliability  correctness, completeness, consistency, robustness  Testability.
Cohesion and Coupling CS 4311
Chapter 12: Design Phase n 12.1 Design and Abstraction n 12.2 Action-Oriented Design n 12.3 Data Flow Analysis n Data Flow Analysis Example n
Design Concepts and Principles Instructor: Dr. Jerry Gao.
Software Engineering Principles. SE Principles Principles are statements describing desirable properties of the product and process.
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
CCSB223/SAD/CHAPTER131 Chapter 13 Designing the System Internals.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
SOFTWARE PROCESS AND PROJECT METRICS. Topic Covered  Metrics in the process and project domains  Process, project and measurement  Process Metrics.
Measurement and quality assessment Framework for product metrics – Measure, measurement, and metrics – Formulation, collection, analysis, interpretation,
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
11 Software Design CSCU 411 Software Engineering.
SOFTWARE DESIGN & SOFTWARE ENGINEERING Software design is a process in which data, program structure, interface and their details are represented by well.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
1 Week 7 Software Engineering Spring Term 2016 Marymount University School of Business Administration Professor Suydam.
Further Modularization, Cohesion, and Coupling. Simple Program Design, Fourth Edition Chapter 9 2 Objectives In this chapter you will be able to: Further.
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
Software Testing.
Coupling and Cohesion 1.
Design Characteristics and Metrics
which satisfies software requirements
Lecture 9- Design Concepts and Principles
Software Design Mr. Manoj Kumar Kar.
CS223: Software Engineering
Software Design CMSC 345, Version 1/11.
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 9.
Chapter 19 Technical Metrics for Software
Communication between modules, cohesion and coupling
Cohesion and Coupling.
Chapter 8: Design: Characteristics and Metrics
Presentation transcript:

Software Metrics and Design Principles

What is Design? Design is the process of creating a plan or blueprint to follow during actual construction Design is a problem-solving activity that is iterative in nature In traditional software engineering the outcome of design is the design document or technical specification (if emphasis on notation)

“Wicked Problem” Software design is a “Wicked Problem” –Design phase can’t be solved in isolation Designer will likely need to interact with users for requirements, programmers for implementation –No stopping rule How do we know when the solution is reached? –Solutions are not true or false Large number of tradeoffs to consider, many acceptable solutions –Wicked problems are a symptom of another problem Resolving one problem may result in a new problem elsewhere; software is not continuous

Systems-Oriented Approach The central question: how to decompose a system into parts such that each part has lower complexity than the system as a whole, while the parts together solve the user’s problem? In addition, the interactions between the components should not be too complicated Vast number of design methods exist

Design Considerations “Module” used often – usually refers to a method or class In the decomposition we are interested in properties that make the system flexible, maintainable, reusable –Information Hiding –System Structure –Complexity –Abstraction –Modularity

Abstraction –Concentrate on the essential features and ignore, abstract from, details that are not relevant at the level we are currently working on –E.g. Sorting Module Consider inputs, outputs, ignore details of the algorithms until later –Two general types of abstraction Procedural Abstraction Data Abstraction

Procedural Abstraction Fairly traditional notion –Decompose problem into sub-problems, which are each handled in turn, perhaps decomposing further into a hierarchy –Methods may comprise the sub-problems and sub- modules, often in time

Data Abstraction From primitive to complex to abstract data types –E.g. Integers to Binary Tree to Data Store for Employee Records Find hierarchy in the data

Modularity During design the system is decomposed into modules and the relationships among modules are indicated Two structural design criteria as to the “goodness” of a module –Cohesion : Glue for intra-module components –Coupling : Strength of inter-module connections

Levels of Cohesion 1.Coincidental Components grouped in a haphazard way 2.Logical Tasks are logically related; e.g. all input routines. Routines do not invoke one another. 3.Temporal Initialization routines; components independent but activated about the same time 4.Procedural Components that execute in some order 5.Communicational Components operate on the same external data 6.Sequential Output of one component serves as input to the next component 7.Functional All components contribute to one single function of the module Often transforms data into some output format

Using Program and Data Slices to Measure Program Cohesion Bieman and Ott introduced a measure of program cohesion using the following concepts from program and data slices: –A data token is any variable or constant in the module –A slice within a module is the collection of all the statements that can affect the value of some specific variable of interest. –A data slice is the collection of all the data tokens in the slice that will affect the value of a specific variable of interest. –Glue tokens are the data tokens in the module that lie in more than one data slice. –Super glue tokens are the data tokens in the module that lie in every data slice of the program Measure Program Cohesion through 2 metrics: - weak functional cohesion = (# of glue tokens) / (total # of data tokens) - strong functional cohesion = (#of super glue tokens) / (total # of data tokens)

1-12 Procedure Sum and Product (N : Integer; Var SumN, ProdN : Integer); VarI : Integer Begin SumN: = 0; ProdN : = 1; For I: = 1to N do begin SumN: = SumN + I ProdN: = ProdN * I End;

1-13 Data Slice for SumN ( N : Integer; Var SumN, ProdN : Integer); VarI : Integer Begin SumN: = 0; ProdN : = 1; For I: = 1to N do begin SumN: = SumN + I ProdN: = ProdN * I End; Data Slice for SumN = N 1 ·SumN 1 ·I 1 ·SumN 2 ·0 1 ·I 2 ·1 2 ·N 2 ·SumN 3 ·SumN 4 ·I 3

1-14 Data Slice for ProdN Data Slice for ProdN = N 1 ·ProdN 1 ·I 1 ·ProdN 2 ·1 1 ·I 2 ·1 2 ·N 2 ·ProdN 3 ·ProdN 4 ·I 4 ( N : Integer; Var SumN, ProdN : Integer); VarI : Integer Begin SumN: = 0; ProdN : = 1; For I: = 1to N do begin SumN: = SumN + I ProdN: = ProdN * I End;

1-15 Data tokenSumNProdN N 1 SumN 1 ProdN 1 I 1 SumN ProdN 21 I N 2 SumN 3 SumN 4 I 3 ProdN 3 ProdN 4 I

1-16 Super Glue S 1 S 2 S 3 IIISuper Glue I IIISuper Glue I IIGlue

1-17 Functional Cohesion Strong functional cohesion (SFC) in this case is the same as WFC SFC = 5/17 = If we had computed only SumN or ProdN then SFC = 17/17 = 1

Coupling Measure of the strength of inter-module connections High coupling indicates strong dependence between modules –Should study modules as a pair –Change to one module may ripple to the next Loose coupling indicates independent modules –Generally we desire loose coupling, easier to comprehend and adapt

Types of Coupling 1.Content –One module directly affects the workings of another –Occurs when a module changes another module’s data –Generally should be avoided 2.Common –Two modules have shared data, e.g. global variables 3.External –Modules communicate through an external medium, like a file 4.Control –One module directs the execution of another by passing control information (e.g. via flags) 5.Stamp –Complete data structures or objects are passed from one module to another 6.Data –Only simple data is passed between modules

Modern Coupling Modern programming languages allow private, protected, public access Coupling may be modified to indicate levels of visibility, whether coupling is commutative Simple Interfaces generally desired –Weak coupling and strong cohesion –Communication between programmers simpler –Correctness easier to derive –Less likely that changes will propagate to other modules –Reusability increased –Comprehensibility increased

Cohesion and Coupling Cohesion Coupling High Level Low Level Strong WeakLoose Tight

1-22 Dharma (1995) Data and control flow coupling –d i = number of input data parameters –c i = number of input control parameters –d o = number of output data parameters –c o = number of output control parameters Global coupling –g d = number of global variables used as data –g c = number of global variables used as control Environmental coupling –w = number of modules called (fan-out) – r = number of modules calling the module under consideration (fan-in)

1-23 Dharma (1995) Coupling metric (m c ) m c = k/M, where k = 1 M = d i + a* c i + d o + b* c o + g d + c* g c + w + r where a=b=c=2 The more situations encountered, the greater the coupling, and the smaller m c One problem is parameters and calling counts don’t guarantee the module is linked to the inner workings of other modules

Henry-Kafura (Fan-in and Fan-out) Henry and Kafura metric measures the inter-modular flow, which includes: –Parameter passing –Global variable access –inputs –outputs Fan-in : number of inter-modular flow into a program Fan-out: number of inter-modular flow out of a program Module’s Complexity, Cp = ( fan-in x fan-out ) 2 for example above: Cp = (3 + 1) 2 = 16 Module, P

Information Hiding Each module has a secret that it hides from other modules –Secret might be inner-workings of an algorithm –Secret might be data structures By hiding the secret, changes do not permeate the module’s boundary, thereby –Decreasing the coupling between that module and its environment –Increasing abstraction –Increasing cohesion (the secret binds the parts of a module) Design involves a series of decisions. For each such decision, questions are: who needs to know about these decisions? And who can be kept in the dark?

Complexity Complexity refers to attributes of software that affect the effort needed to construct or change a piece of software –Internal attributes; need not execute the software to determine their values Many different metrics exist to measure complexity Two broad classes –Intra-Modular attributes –Inter-Modular attributes

Intra-Modular Complexity Two types of intra-modular attributes –Size-Based Metrics E.g. Lines of Code –Obvious objections but still commonly used –Structure-Based Metrics E.g. complexity of control or data structures

Halstead’s Software Science Size-based metric Uses number of operators and operands in a piece of software –n 1 is the number of unique operators –n 2 is the number of unique operands –N 1 is the total number of occurrences of operators –N 2 is the total number of occurrences of operands Halstead derives various entities –Size of Vocabulary: n = n 1 +n 2 –Program Length: N = N 1 +N 2 –Program Volume: V = Nlog 2 n Visualized as the number of bits it would take to encode the program being measured

Halstead’s Software Science –Potential Volume: V* = (2+n 2 )log(2+n 2 ) V* is the volume for the most compact representation for the algorithm, assuming only two operators: the name of the function and a grouping operator. n 2 is minimal number of operands. –Program Level: L = V*/V –Programming Effort: E = V/L –Programming Time in Seconds: T = E/18 –Numbers derived empirically, also based on speed human memory processes sensory input Halstead metrics really only measures the lexical complexity, rather than structural complexity of source code.

Software Science Example 1.procedure sort(var x:array; n: integer) 2.var i,j,save:integer; 3.begin 4.for i:=2 to n do 5.for j:=1 to i do 6.if x[i]<x[j] then 7.beginsave:=x[i]; 8.x[i]:=x[j]; 9.x[j]:=save 10.end 11.end

Software Science Example Operator# procedure 1 sort()1 var2 :3 array1 ;6 integer2,2 begin…end2 for..do2 if…then1 :=5 <1 []6 n1=14N1=35 Operand# x7 n2 i6 j5 save n2=7N2=25 Size of vocabulary: 21 Program length:60 Program volume:264 Program level:0.04 Programming effort:6000 Estimated time:333 seconds

Structure-Based Complexity McCabe’s Cyclomatic Complexity Create a directed graph depicting the control flow of the program –CV = e – n + 2p CV = Cyclomatic Complexity e = Edges n = nodes p = connected components

Cyclomatic Example 12 For Sorting Code; numbers refer to line numbers CV = 13 – *1 = 4 McCabe suggests an upper limit of 10 T.J. McCabe’s Cyclomatic complexity metric is based on the belief that program quality is related to the complexity of the program control flow.

Shortcomings of Complexity Metrics Not context-sensitive –Any program with five if-statements has the same cyclomatic complexity –Measure only a few facts; e.g. Halstead’s method doesn’t consider control flow complexity Others? Minix: –Of the 277 modules, 34 have a CV > 10 –Highest has 58; handles ASCII escape sequences. A review of the module was deemed “justifiably complex”; attempts to reduce complexity by splitting into modules would increase difficulty to understand and artificially reduce the CV

System Structure – Inter-Module Complexity The design may consist of modules and their relationships Can denote this in a graph; nodes are modules and edges are relationships between modules Types of inter-module relationships: –Module A contains Module B –Module A follows Module B –Module A delivers data to Module B –Module A uses Module B We are mostly interested in the last one, which manifests itself via a call graph –Possible shapes: Chaotic Directed Acyclic Graph (Hierarchy) Layered Graph (Strict Hierarchy) Tree

Module Hierarchies

Graph Metrics Metrics use: –Size of the graph –Depth –Width (maximum number of nodes at some level) A tree-like call graph is considered the best design –Some metrics measure the deviation from a tree; the tree impurity of the graph –Compute number of edges that must be removed from the graph’s minimum spanning tree Other metrics –Complexity(M) = fanin(M)*fanout(M) –Fanin/Fanout = local and global data flows

1-38 Software Metrics Etiquette Use common sense and organizational sensitivity when interpreting metrics data. Provide regular feedback to the individuals and teams who have worked to collect measures and metrics. Don’t use metrics to appraise individuals Work with practitioners and teams to set clear goals and metrics that will be used to achieve them. Never use metrics to threaten individuals or teams. Metrics data that indicate a problem area should not be considered “negative”. These data are merely an indicator for process improvement. Don’t obsess on a single metric to the exclusion of other important metrics.