We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17
Object-Oriented Metrics
Instructor: Muhammad Zeeshan Nazar
Object-Oriented Metrics • CK Metrics • Proposed by Chidamber and Kemerer • Class-based metrics • LK Metrics • Proposed by Lorenz and Kidd • Class-based and operation-based • MOOD Metrics • Proposed by Harrison, Counsell, and Nithi • Class-based CK Metrics • Weighted methods per class (WMC) • WMC = number of methods defined in class • The sum of the complexity values for all the methods of a given class. • They do not specify the specific complexity metric to use (e.g., cyclomatic complexity). • A high WMC has been found to lead to more faults. WMC should be kept low. • Classes with many methods are likely to be more application specific, limiting the possibility of reuse. • WMC is a predictor of how much time and effort is required to develop and maintain the class. The higher the value, the more effort required. CK Metrics • Weighted methods per class (WMC) • A possible indication of reusability. • A large number of methods also means a greater potential impact on derived classes, since the derived classes inherit (some of) the methods of the base class. • Search for high WMC values to spot classes that could be restructured into several smaller classes. CK Metrics • Depth of inheritance tree (DIT) • DIT = maximum inheritance path from the class to the root class • The length of the longest path from the root of the inheritance hierarchy to a leaf class. • As DIT increases, the lower classes in the hierarchy inherit a greater number of data and methods, thus making their behavior more difficult to understand and causing testing to require more effort. • A large DIT value implies greater design complexity, but also greater reuse. CK Metrics • Number of children (NOC) • NOC = number of immediate sub-classes of a class • A count of the number of classes immediately subordinate to a given class in the hierarchy. • A high NOC, a large number of child classes, can indicate several things: High reuse of base class. Inheritance is a form of reuse. Base class may require more testing. Improper abstraction of the parent class (too generic or too specific). Misuse of sub-classing. In such a case, it may be necessary to group related classes and introduce another level of inheritance. CK Metrics • Coupling between classes (CBO) • CBO = number of classes to which a class is coupled • The amount of collaboration and interaction between a given class and the other classes in the system. • As the CBO value increases, reusability decreases. • The more independent a class is, the easier it is to reuse it in another application. • Also, a high CBO indicates potential difficulty in modifying the class and the subsequent testing of the modifications. • CBO should be kept low. CK Metrics • Response for a class (RFC) • The number of methods that can potentially be executed in response to a message received by an object of a given class. • RFC = M + R • M = number of methods in the class • R = number of remote methods directly called by methods of the class • As the RFC value increases, testing effort and design complexity also increase. • RFC should be kept low. CK Metrics • Lack of cohesion in methods (LCOM) • The number of methods in a given class that access one or more of the same instance variables. • If no methods access the same attributes, then LCOM = 0. • To illustrate the case where LCOM ≠ 0, consider a class with six methods. Four of the methods have one or more attributes in common (i.e., they access common attributes). Therefore, LCOM = 4. • If LCOM is high, methods may be coupled to one another via attributes. • The higher the LCOM value, the lower the cohesion of methods, and greater the coupling. • A high LCOM value could indicate the need to break the class apart into multiple classes. LK Metrics • Class size (CS) • The total number of methods (both inherited and local) plus the total number of attributes (both inherited and local) encapsulated by a given class. • Inherited members should be weighted more heavily than local members. • Large values of CS could indicate that the class is too large, that it encapsulates too much behavior, structure, and responsibility. • High CS values may also indicate lower reusability. LK Metrics • Number of operations overridden by a subclass (NOO) • A count of the methods in subclasses that have been redefined. • Large NOO values could indicate a design problem, since the model of the class seems to be violated. • Since a subclass should be a specialization of its super classes, it should primarily extend the services [operations] of the super classes. This should result in unique new method names. LK Metrics • Number of operations added by a subclass (NOA) • A count of the new methods appearing in subclasses. • A large NOA value could indicate a design abstraction violation. • As CK DIT increases, NOA should decrease. LK Metrics • Specialization index (SI) • The degree to which subclasses are differentiated from super classes. • SI is computed as NOO multiplied by the level at which the class resides in the inheritance hierarchy divided by the total number of methods defined by the class. SI = (NOO * depth) / (total number of class methods) • A high SI could indicate a lack of conformance to superclass abstractions. LK Metrics • Average operation size (OSavg) • Average Operation Size (OSavg) is a metric used to measure the size or complexity of operations (methods/functions) within a class. • It quantifies the average number of messages sent by methods within a specific class. • When a method within a class sends out a high number of messages, it means that the method is interacting with various other methods, classes, or components. • A high OSavg value suggests that the methods within a class are doing a lot of work by interacting with many other parts of the system. • A high OSavg value can indicate a poor allocation of responsibility within the class. LK Metrics • Operation complexity (OC) • Operation Complexity (OC) is a metric used to evaluate the complexity of methods or operations within a class. • It often measures aspects like cyclomatic complexity, which assesses the number of independent paths within a method. • OC should be kept as low as possible. LK Metrics • Average number of parameters per operation (NPavg) • The Average number of parameters per operation (NPavg) is a metric that measures the average size of parameter lists in methods or functions within a class or system. • Should be kept low Reference • Software Engineering: Theory and Practice, Shari Lawrence Pfleeger and Joanne M. Atlee, 4th Edition, Pearson, 2009.