Software Metrics for Object Oriented Design

Slides:



Advertisements
Similar presentations
SPEC Workshop 2008 Laboratory for Computer Architecture1/27/2008 On the Object Orientedness of C++ programs in SPEC CPU 2006 Ciji Isen & Lizy K. John University.
Advertisements

Software Metrics Software Engineering.
Prediction of fault-proneness at early phase in object-oriented development Toshihiro Kamiya †, Shinji Kusumoto † and Katsuro Inoue †‡ † Osaka University.
Figures – Chapter 24.
Metrics for Object Oriented Design Shyam R. Chidamber Chris F. Kemerer Presented by Ambikadevi Damodaran.
Applying and Interpreting Object Oriented Metrics
March 25, R. McFadyen1 Metrics Fan-in/fan-out Lines of code Cyclomatic complexity Comment percentage Length of identifiers Depth of conditional.
Nov R. McFadyen1 Metrics Fan-in/fan-out Lines of code Cyclomatic complexity* Comment percentage Length of identifiers Depth of conditional.
Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering.
Object-Oriented Metrics. Characteristics of OO ● Localization ● Encapsulation ● Information hiding ● Inheritence ● Object abstraction.
Design Metrics Software Engineering Fall 2003 Aditya P. Mathur Last update: October 28, 2003.
Software engineering for real-time systems
© S. Demeyer, S. Ducasse, O. Nierstrasz Duplication.1 7. Problem Detection Metrics  Software quality  Analyzing trends Duplicated Code  Detection techniques.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-Oriented Metrics
March R. McFadyen1 Software Metrics Software metrics help evaluate development and testing efforts needed, understandability, maintainability.
1 Complexity metrics  measure certain aspects of the software (lines of code, # of if-statements, depth of nesting, …)  use these numbers as a criterion.
Predicting Class Testability using Object-Oriented Metrics M. Bruntink and A. van Deursen Presented by Tom Chappell.
Object Oriented Metrics XP project group – Saskia Schmitz.
Comp 587 Parker Li Bobby Kolski. Automated testing tools assist software engineers to gauge the quality of software by automating the mechanical aspects.
Software Metrics.
Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009.
Lecture 17 Software Metrics
Chidamber & Kemerer Suite of Metrics
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Refactoring.
Object-Oriented Metrics Alex Evans Jonathan Jakse Cole Fleming Matt Keran Michael Ababio.
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.
Software Measurement & Metrics
The CK Metrics Suite. Weighted Methods Per Class b To use this metric, the software engineer must repeat this process n times, where n is the number of.
1 OO Metrics-Sept2001 Principal Components of Orthogonal Object-Oriented Metrics Victor Laing SRS Information Services Software Assurance Technology Center.
The CK Metrics Suite. Weighted Methods Per Class b To use this metric, the software engineer must repeat this process n times, where n is the number of.
Concepts of Software Quality Yonglei Tao 1. Software Quality Attributes  Reliability  correctness, completeness, consistency, robustness  Testability.
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.
Procedural programming in Java Methods, parameters and return values.
1 Metrics and lessons learned for OO projects Kan Ch 12 Steve Chenoweth, RHIT Above – New chapter, same Halstead. He also predicted various other project.
An Automatic Software Quality Measurement System.
CSc 461/561 Information Systems Engineering Lecture 5 – Software Metrics.
Measurement and quality assessment Framework for product metrics – Measure, measurement, and metrics – Formulation, collection, analysis, interpretation,
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Object-Oriented (OO) estimation Martin Vigo Gabriel H. Lozano M.
Ontology Support for Abstraction Layer Modularization Hyun Cho, Jeff Gray Department of Computer Science University of Alabama
Object Oriented Metrics
Software Engineering Lecture 19: Object-Oriented Testing & Technical Metrics.
1 OO Technical Metrics CIS 375 Bruce R. Maxim UM-Dearborn.
Software Engineering Object Oriented Metrics. Objectives 1.To describe the distinguishing characteristics of Object-Oriented Metrics. 2.To introduce metrics.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
CS223: Software Engineering Lecture 21: Unit Testing Metric.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
1 Week 7 Software Engineering Spring Term 2016 Marymount University School of Business Administration Professor Suydam.
Design Metrics CS 406 Software Engineering I Fall 2001 Aditya P. Mathur Last update: October 23, 2001.
Object Oriented Metrics
A Hierarchical Model for Object-Oriented Design Quality Assessment
What is an Object Objects are key to understanding object-oriented technology. An object can be considered a "thing" that can perform a set of related.
Software Metrics 1.
Inheritance ITI1121 Nour El Kadri.
Course Notes Set 12: Object-Oriented Metrics
Design Characteristics and Metrics
Object Oriented Programming in Java
Object-Oriented Metrics
Design Metrics Software Engineering Fall 2003
A Pluggable Tool for Measuring Software Metrics from Source Code
Design Metrics Software Engineering Fall 2003
Information flow-Test coverage measure
Mei-Huei Tang October 25, 2000 Computer Science Department SUNY Albany
Software Metrics SAD ::: Fall 2015 Sabbir Muhammad Saleh.
Software Metrics using EiffelStudio
Object-Oriented PHP (1)
Chapter 8: Design: Characteristics and Metrics
Presentation transcript:

Software Metrics for Object Oriented Design CK and MOOD Metrics Eric Gitangu Manali Patel

Outline Definition and Use of Software Metrics. CK and Mood Metrics with Examples Conclusion

Use of Software Metrics Software development is an integral part of software industry, which involves: the process of analyzing software requirements, designing specifications for the requirements gathered from the analysis stage, writing, testing and maintenance of the code up to the retirement of a piece of software. There are understated steps that relate to the planning phase of software engineering that include: research, determining the cost, size, capacity, products and structuring prior to the implementation are usually not considered yet equally as important to the software development process. How metrics could help during different phases such as Implementation and debugging the code?

Use of Software Metrics A software engineer could create a metric to narrow down the scope of possible fault or error locations during the debugging process and also to provide an insight to improve our implementation methods. provide the special cases that need to be addressed before the product release. To Track the product improvement process.

Software Metrics As an aid to the software industry, software metrics have been introduced to help improve the implementation process, testing and maintenance of the product.   A Software Metric offers a quantitative approach to measure a particular property of a piece of Software.

Object Oriented Metrics Chidamber and Kemerer (CK) metrics suite (1994) Weighted Methods per Class (WMC) Coupling between Objects (CBO) Response set of a Class (RFC) Depth of Inheritance Tree (DIT) Number of Children (NOC) Lack of Cohesion (LCOM) Metrics of Object-Oriented Design (MOOD) by Abreu (1995) Method Inheritance Factor (MIF) Attribute Inheritance Factor (AIF) Attribute Hiding Factor (AHF) Method Hiding Factor (MHF) Polymorphism Factor (POF) Coupling Factor (CF)

Cohesion Coupling Inheritance Complexity Encapsulation Polymorphism Lack of Cohesion (LCOM) Coupling Coupling between Objects (CBO) - CK Response set of a Class (RFC) - CK Coupling Factor (CF) - MOOD Inheritance Depth of Inheritance Tree (DIT) - CK Number of Children (NOC) - CK Method Inheritance Factor (MIF) - MOOD Attribute Inheritance Factor (AIF) - MOOD Complexity Weighted Methods per Class (WMC) - CK Encapsulation Attribute Hiding Factor (AHF) - MOOD Method Hiding Factor (MHF) - MOOD Polymorphism Polymorphism Factor (POF) - MOOD

Complexity – WMC

WMC Weighted Methods per Class Counts the Weighted sum of all the methods per class. Measure the level of Complexity of a class WMC is known as sum of Cyclomatic complexities of all the methods . Minimum WMC is 1 because class should be consist of at least one method. Higher WMC = High Complexity Lower WMC = Easier to reuse, maintain, test For example if 0 < V (G) < 10 corresponds to less and easy to test code. 10 < V (G) < 20 corresponds to moderate complex code which is moderately easy to test. V(G) > 40 refers to very complex code which for the most part is impossible to test.

Cyclomatic complexities (1) CC = Number of Conditions + 1 The control flow graph (2) V(G) = E – N + 1 (As the exist point loops back to the entry point) (3) V(G) = E – N + 2

WMC - To Calculate Cyclomatic Complexities // V(G) = +1 if( r1() ) { //V(G) = +2 m1(); } else { m2(); } if( r2() ) { //V(G) = +3 m3(); } m4(); } Each method has base complexity as 1 IF….Else with single decision = +1 if (c>3 || c < 20) = +2 because 2 conditions Case = +1 While loop = +1

WMC - To Calculate Cyclomatic Complexities V(G) = 9E – 7N + 1 V(G) = 9E – 8N + 2 = 3 = 3

Inheritance – DIT NOC MIF AIF

DIT Depth of Inheritance Tree Calculates the length/depth of inheritance level from the class to the inheritance tree i.e. the longest path from the class to its root. The DIT is the count of the level of subclasses effecting a class. The value 0 of the DIT indicates a root with no subclasses. High DIT -> deeper inheritance -> the complexity of the class becomes greater -> increases the number of faults as more methods and variable have been reused leading to increased coupling.

DIT Example DIT level of subclass 4 and 5 is = 2

NOC Number of Children (NOC) counts the number of subclasses derived from a class and measures the breadth of the class. NOC is counting the number of times the parent class methods have been inherited by subclasses.   Increased NOC ->indicates higher modularity -> reduces the probability of errors arising and also promotes reusability since with higher modularity we may be able to debug individual modules separately hence a lower probability of error detection.

NOC Example There are 9 classes that inherits the class A and therefore NOC = 9

MIF Method Inheritance factor MIF = inherited methods/total methods available in classes i.e. the ratio of inherited methods to total number methods of available classes. Both MIF and AIF should be maintained at mediocre ratios since too high a ratio of either indicates excessive inheritance and too low a ratio indicates a poor object-oriented framework.

#include <iostream> MIF = inherited methods/ total methods using namespace std; = 2/3 = 0.6 class A { public: A() { a_member = 0; } protected: int a_member; class B{ B() { b_member = 0; } int b_member; }; class C : public A, public B { C() : A(), B() { c_member = 0; } int c_member; };

AIF Attribute Inheritance Factor AIF = inherited attributes/total attributes available in classes i.e. the ratio of inherited attributes to the total number of attributes.

AIF = inherited attributes/total attributes available in classes = 2/4 class Polygon { protected: int width, height, x, y; //4 public: void setParameters (int w, int h); { width = w; height = h; } }; class Rectangle : public Polygon //inheriting from Polygon { public: int calculateArea () { return (width*height); } }; // inheriting 2 attributes int main () { ….} AIF = inherited attributes/total attributes available in classes = 2/4 = 0.5

Coupling – CBO RFC CF By Eric

CBO Coupling Between Objects counts the number of classes coupled with a considered class. High coupling between classes -> increases the complexity of the class and makes it difficult to reuse and test the program. It is also difficult to maintain and increases the number of errors/faults since the larger number of coupling requires more time and deeper understanding while making changes to improve the product. Therefore, the object coupling between classes should be minimum. Coupling considerably increases when we have methods of one class calling or using attributes associated with another class.

CBO Example Class F has the coupling relation with class A,B,C and E CBO = 4 public class Class F extends Class E implements Serializable { ClassB objB; public Class C foo( ClassA objA) throws Exception{ int noConstants = Constant.MAX_VAL; try(objB.isGreaterThan(objA)) { noConstants = objA .getValue(); } Catch (Exception ex) {ex.stacktrace();} return new ClassC ();

RFC Response set of a Class It is the set of methods that are invoked in the response of a message to a class. As the number of outcomes increases, the class’ complexity becomes higher. For example, when we are dynamically allocating new objects within a thread of execution we may create numerous objects within the thread, the RFC would determine the total number of outcomes that would evolve from execution of the thread or an instance of a class. As the result, RFC becomes higher and as the understanding of the interaction between objects becomes harder, the testing and debugging problem increases.

RFC Example Class Pump { void firstmethod() { secondmethod(): } void secondmethod() thirdmethod(): void thirdmethod() System.Out.Println(“We called 3 methods on response to new pump”); Public Static void main(String [] args) Pump mypump = new Pump(); mypump.firstmethod(); RFC = 4 (including println)

CF Coupling Factor It is the ratio of actual coupling vs. maximum number of potential coupling in a class It is measured as percentage from 0% - 100%. We ideally thrive for low coupling i.e. independence coupling. In computational terms we thrive for a CF level of <=10% out of a maximum 100%.

CF Example #include <iostream> using namespace std; class A { public: A() { a_member = 0; } protected: int a_member; class B{   B() { b_member = 0; }  int b_member; }; class C : public A, public B { C() : A(), B() { c_member = 0; } //Calling methods of another class int c_member; }; CF = actual coupling / maximum number of potential coupling among classes = 2/10 = 20%

Cohesion - LCOM

LCOM LCOM measure the level of cohesion and is used to determine the lack of cohesion. It is about measuring the number of the pair methods that have shared the at least one(Q) or different set of variables in a class(P). Based on the pair methods, we increase P or Q by one where LCOM = P - Q, if P> Q otherwise LCOM = 0. The class is considered to be highly cohesive if LCOM = 0 and if  LCOM > 0, then a class is not well cohesive and the higher value of LCOM can result into fault or error.

LCOM Example 1 public class A { To measure LCOM private int f2; Compare two methods Private int f3; if share variable increase Q Private int f4; if no share variable increase P Private int f5; public void method1() { // Uses f1; method 1 & method 2 -> Q = 1 // Uses f2; } method 1 & method 3 -> P = 1 public void method2() { method 2 & method 3 -> P = 2 // Uses f2; // Uses f3; } LCOM = P-Q if P>Q public void method3() { LCOM = 1 // Uses f4; // Uses f5; }

LCOM Example 2 LCOM = 8 LCOM = 8 P = 9 P = 18 Q = 1 Q = 10

Encapsulation – MHF AHF

MHF Method Hiding Factor It is a fraction in which the denominator is the number of total methods whereas the numerator is the total of encapsulated methods defined in all the classes. If all methods are private/protected, MHF = 100%, High encapsulation decreases the complexity since encapsulated methods dictate the scope from which they may be accessed therefore limiting the number of locations which makes the debugging process easier. If all methods are public, MHF = 0% shows methods are unprotected and chances of errors are high.

MHF Example class Polygon { protected: int width, height; public: void setParameters (int w, int h); { width = w; height = h; } }; class Rectangle : public Polygon { public: int calculateArea () { return (width*height); } }; class Triangle : public Polygon { public int calculateArea () { return( (width*height)/2); } }; MHF = the total of encapsulated methods/ total methods = 0

AHF Attribute Hiding Factor It measures the total number of attributes encapsulated in the class. The AHF  may be expressed as a fraction in which the denominator is the number of total attributes whereas the numerator is the total of encapsulated attributes defined in all the classes. If all attributes are private/protected – MHF = 100%. If all attributes are public – MHF = 0% shows methods are unprotected and chances of errors are high. Same as MHF

AHF Example #include <iostream> using namespace std; class A { public: A() { a_member = 0; } protected: int a_member; class B{   B() { b_member = 0; }  int b_member; }; class C : public A, public B { C() : A(), B() { c_member = 0; } int c_member; }; AHF = the total of encapsulated attributes/ total attributes = 2/3 = .6667

Polymorphism - PF

PF Polymorphism Factor It is the ratio of number of overridden methods in the class vs the maximum number of methods that can be overridden. POF becomes higher with more overriding and the increases the level of complexity and lower with less overridden to the base class. POF is expressed as a percentage between 0% - 100%, as aforesaid, when PF=100%, all methods are overridden in all derived classes and correlates to a complex program. A PF value of 0% may indicates that a project uses no inheritance, polymorphism. We ideally want the PF value to range between 40% - 60% this would indicate a moderately complex program which correlates to a moderately hard program to test and or maintain.

class Animal { public: virtual void eat() { std::cout << "I eat like a generic animal.\n"; } virtual ~Animal() { } }; class Wolf : public Animal { void eat() { std::cout << "I eat like a wolf!\n"; } void tasteWolf() {} class Fish : public Animal { void eat() { std::cout << "I eat like a fish!\n";} void tasteFish() {} PF = number of overridden methods/the maximum number of methods that can be overridden. = 1/3 = 0.3333

Conslusion The object oriented paradigm is increasingly being used in the software industry such as Java, C++, C#, .NET Framework etc. The increased demand for Object-Oriented designs has necessitated the need for the adoption of well-defined structures that the CK and MOOD suite provides. CK and MOOD provide a medium through which software engineers can build robust, easy to maintain, relatively cheaper and more importantly provide a quantitative way of measuring the success of a project.

Conslusion

Kaur, Amandeep, Satwinder Singh, Dr. K. S. Kahlon, and Dr Kaur, Amandeep, Satwinder Singh, Dr. K. S. Kahlon, and Dr. Parvinder Sandhu. "Empirical Analysis of CK & MOOD Metric Suit.“ Ed. International Journal of Innovation, Management and Technology. Vol. 1December 5,2010. 1-6. Print. Shaik, Amjan, C.R.K Reddy, Bala Manda, Prakashini C., and Deepthi K. "Metrics for Object Oriented Design Software Systems: A Survey.” Ed. Journal of Emerging Trends in Engineering and Applied SciencesScholarlink Research Institute Journals, 2010. 1-9. Print.

Questions? Comments?