Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Metrics

Similar presentations


Presentation on theme: "Object Oriented Metrics"— Presentation transcript:

1 Object Oriented Metrics
Group 5: Luke Swanson, Paul DeBruyne, Alex Martin, Erik Matchette, Paul Mauer

2 Overview

3 Overview: Object-Oriented Metrics
OO Metrics: What are they? Quantitative measurement of the qualities of OO design Coupling Cohesion Encapsulation Inheritance Complexity Goal: Measure the effectiveness of OO techniques in a design

4 Metrics

5 Depth of Inheritance Tree - Overview
Measures the maximum length from a node to the root (base class) Three assumption about DIT: The deeper a class in the hierarchy, the greater the number of methods it will probably inherit which makes it harder to predict its behavior. Deeper trees involve greater design complexity since more classes and methods are involved. Deeper classes in the tree have a greater potential for reusing inherited methods. Typically upper limit is 5-6

6 Depth of Inheritance Tree - Example
B C D B C D E F E F DIT = 3 Bottom Heavy DIT = 2 Balanced tree G H I J

7 Number of Children - Overview
Is a measure of the number of immediate subclasses of a class in a hierarchy Viewpoints: The more children the more reuse More children might mean improper abstraction More children might indicate greater importance

8 Number of Children - Example
A has 3 children C has none

9 Number of Operations Overridden (NOO)
Number of inherited operations that are redefined by the class A large number for NOO indicates possible problems with the design Poor abstraction in inheritance hierarchy Implies too big a difference with the parent class → inheritance then makes less sense A class which inherits services must use them with a minimum number of modifications

10 Number of Operations Overridden (NOO) - Example
class ParentClass { int x; int getResult() { return x; } } class ChildClass extends ParentClass { int y; int getResult() { return x + y; } } 1

11 Number of Operations Added (NOA)
The number of operations added by a subclass As operations are added it moves further away from the superclass As depth increases, NOA should decrease

12 Number of Operations Added (NOA) - Example
class ParentClass { int x, y, z; int getResult() { return x; } } class ChildClass1 extends ParentClass { int doSomething1() { return x + y; } int doSomething2() { return x + z; } } class ChildClass2 extends ChildClass1 { int doSomething3() { return y + z; } } 1 2

13 Class Size (CS) Total number of operations (inherited, private, public) plus Total Number of attributes (inherited, private, public) May be an indication of too much responsibility for a class

14 Class Size (CS) - Example
class ParentClass { int x, y, z; int getResult() { return x; } } class ChildClass1 extends ParentClass { int doSomething1() { return x + y; } int doSomething2() { return x + z; } } class ChildClass2 extends ChildClass1 { int doSomething3() { return y + z; } } 7 4 6

15 Method Inheritance Factor - Overview
System level metric - measures how many methods in a system are inherited, and how many are overridden Ratio of the sum of inherited methods in all classes of the system to the total number of methods available for all classes Expressed as a value between 0 and 1, where 0 means no inherited methods are used, and 1 means all methods are inherited A Method Inheritance Factor between 0.2 and 0.8 is ideal for increased reliability and reduced testing effort

16 Method Inheritance Factor - Formula
n = the total number of classes in the system Mi(Ci) = the number of methods inherited but not overwritten in class Ci Ma(Ci) = the number of methods that can be invoked in class Ci (includes inherited methods, overridden methods, new methods)

17 Method Inheritance Factor - Demonstration
Shape Mi = 0 Ma = 6 Triangle Mi = 5 Ma = 9 Rectangle Mi = 5 Ma = 6

18 Polymorphism Factor - Overview
Measures the degree of method overriding in a class inheritance tree Ratio of the number of method overrides over the maximum number of possible method overrides Expressed as a value between 0 and 1, where 0 means no overridden methods are used, and 1 means all methods are overridden

19 Polymorphism Factor - Formula
TC = total number of classes in the class hierarchy Mo(Cj) = Number of overriding methods of class Cj Mn(Ci) = Number of new methods of class Ci DC(Ci) = Number of descendant classes of class Ci

20 Polymorphism Factor - Demonstration
Shape Mo = 0 Mn = 6 Dc = 2 Triangle Mo = 1 Mn = 3 Dc = 0 Rectangle Mo = 1 Mn = 0 Dc = 0

21 Weighted Methods per Class
Use another measure of complexity to determine overall class difficulty. Examples: Halstead’s complexity metrics (length, vocabulary, volume, etc). McCabe’s graph-based metrics. Complexity of all class methods is summed to obtain final complexity value. Equation: 𝛴ci = WMC ci is complexity of ith method.

22 Weighted Methods per Class - Example
Using McCabe’s cyclomatic complexity. Class: Vector Method: Insert Remove Sort isEmpty Clear Find Complexity: 3 2 4 1

23 Weighted Methods per Class - Example
Using McCabe’s cyclomatic complexity. Class: Vector Class complexity: WMC = = ? Method: Insert Remove Sort isEmpty Clear Find Complexity: 3 2 4 1

24 Weighted Methods per Class - Example
Using McCabe’s cyclomatic complexity. Class: Vector Class complexity: WMC = = 15 Method: Insert Remove Sort isEmpty Clear Find Complexity: 3 2 4 1

25 Weighted Methods per Class
Indicates general level of effort needed to develop/maintain the class. Less useful for small systems, becomes more useful for deep inheritance trees. High complexity classes can lead to high difficulty maintaining subclasses.

26 Response for a Class Equation: RS = Mc ∪ Me; |RS| = RFC.
Number of methods that may be called in response to a class’s actions. To find RFC: Determine all external functions called by class methods. Take the union of that set and the set of class methods, called the response set (RS). RFC is simply the size of RS. Equation: RS = Mc ∪ Me; |RS| = RFC. Mc is set of class methods, Me is set of external methods called.

27 Response for a Class - Example
List of objects in a game. Class: ObjectList Method: Insert Remove Move isEmpty Clear Find Show External Calls: ~object move equals draw

28 Response for a Class - Example
List of objects in a game. Class: ObjectList Mc = {Insert, Remove, Move, isEmpty, Clear, Find, Show} Method: Insert Remove Move isEmpty Clear Find Show External Calls: ~object move equals draw

29 Response for a Class - Example
List of objects in a game. Class: ObjectList Mc = {Insert, Remove, Move, isEmpty, Clear, Find, Show} Me = {~object, move, equals, draw} Method: Insert Remove Move isEmpty Clear Find Show External Calls: ~object move equals draw

30 Response for a Class - Example
List of objects in a game. Class: ObjectList Mc = {Insert, Remove, Move, isEmpty, Clear, Find, Show} Me = {~object, move, equals, draw} RS = {Insert, Remove, Move, isEmpty, Clear, Find, Show, ~object, move, equals, draw} Method: Insert Remove Move isEmpty Clear Find Show External Calls: ~object move equals draw

31 Response for a Class - Example
List of objects in a game. Class: ObjectList RS = {Insert, Remove, Move, isEmpty, Clear, Find, Show, ~object, move, equals, draw} RFC = |RS| = ? Method: Insert Remove Move isEmpty Clear Find Show External Calls: ~object move equals draw

32 Response for a Class - Example
List of objects in a game. Class: ObjectList RS = {Insert, Remove, Move, isEmpty, Clear, Find, Show, ~object, move, equals, draw} RFC = |RS| = 11 Method: Insert Remove Move isEmpty Clear Find Show External Calls: ~object move equals draw

33 Response for a Class May be seen as a measure of object cohesion and coupling (or lack of). High RFC could indicate high coupling, or low cohesion. Low RFC may indicate opposite. Not very specific, however. High response for a class may lead to: More extensive test sets. More difficulty in understanding class. Less reusability. More time and effort needed to fix.

34 Coupling between Object Classes (CBO)
Definition: The number of classes to which a class is coupled with Per class basis Coupling: method uses methods/instance variables of another class Goal: Lower CBO the Better Coupling is best kept to a minimum Promotes modular design Reuse Easier Maintenance

35 Coupling between Object Classes (CBO) Example

36 Lack of Cohesion in Methods (LCOM)
Definition: # of not connected method pairs in a class Connected: methods in a class reference a same instance variable(s) Shows cohesion: operate on same data Per class basis Goal: LCOM4 = 1 Represents a cohesive class

37 LCOM4 Example

38 Questions?


Download ppt "Object Oriented Metrics"

Similar presentations


Ads by Google