Object Oriented Metrics in SE
Object Oriented Metrics in SE
Booch defines object oriented design to be the process of identifying objects and their
attributes, identifying operations required on each object and establishing interfaces between
objects.
Design of classes involves three steps:
1) definition of objects
2) attributes of objects and
3) communication between objects.
Methods design involves defining procedures which implement the attributes and
operations suffered by objects. Class design is therefore at a higher level of abstraction than the
traditional data/procedures approach (which is closer to methods design). It is the task of class
design that makes OOD different than data/procedure design [Taylor & Hechi, 1990]. An
introduction to the fundamental concepts and terminology of object-oriented design is as shown
below
Some of the terminologies commonly used in object oriented metrics are as follows
Object Oriented
Class Super
Attribute(s)
Method(s)
Message 1
In the above diagram the class Super is the super class of sub1, sub2, and sub3 classes.
Here these three classes are acquiring the attributes and methods from its base class Super in
addition to having its own attributes and operations. A sub class can also become a super class
for other classes forming hierarchical structure. When an object is created to contain data or
information, it is an instantiation of the class. Two objects obj1 and obj2 are the objects of sub1
and sub2 classes respectively. Classes communicate or interact by passing messages. When a
message is passed between two objects, the classes are coupled. Message 1 is the way of
coupling two objects.
The selected object oriented metrics are primarily applied to the classes, coupling, and
inheritance. For some of the object-oriented metrics discussed here, multiple definitions are
given; developers, researchers and practitioners have not reached a common definition. In some
cases, the counting method for a metric is determined by the software analysis package being
used to collect the metrics. Object oriented metrics are categorized like size, coupling, cohesion,
inheritance etc.
A class is a blue print/template from which objects can be instantiated. This set of objects
shares a common structure and a common behavior defined by the set of methods. A method is a
set of instructions that performs an operation upon an object and is defined in the class definition.
A message is the way of communicating an object with another object to perform required
operation. The operation executed as a result of receiving a message is called a method.
Cohesion is defined as the degree to which the elements of a module belong together. It is a
measure of how tightly related each piece of functionality expressed by the source code of a
software module. Effective object oriented designs maximize cohesion because cohesion
promotes encapsulation. In software engineering, coupling is the manner and degree of
interdependence between software modules; a measure of how closely connected two routines or
modules are; the strength of the relationships between modules. Classes (objects) are coupled
when a message is passed between objects; when methods declared in one class use methods or
attributes of another class. Inheritance is the process of acquiring the attributes and methods of
one class into another class in hierarchical relationship among classes that enables programmers
to reuse previously defined objects including variables and operations.
class Person
pid , pname , age, gen
setData(),getData()
The size metrics given here measure the size of the system in terms of attributes and
methods included in the class and capture the complexity of the class.
delete(),getData(), display()
Coupling Metrics
In Figure 4, the Book class contains instances of classes Publications and Sales.
The Book class delegates its publication and sales issue to instances of the publication
and sales classes. The value of metric CBO for class book is 2 and for class Publication
and Sales is zero (0).
In Figure 4, MPC value of class Book is 4 as methods in class book calls pub.getData (),
pub.display (), market.setData (), market.display () methods.
Coupling due to the use of the inheritance is not included in CF, because a class is
heavily coupled to its ancestors via inheritance. If no classes are coupled, CF=0%. If all
classes are coupled with all other classes, CF=100%.
Cohesion Metrics
Cohesion is the measure of the degree to which the elements of a module are
functionally related. A strongly cohesive model implements functionality that is related to
one feature of the software and requires little or no interaction with other modules. We
have to maximize the interactions within a module.
Boo
k
Book_id,pub_i
d, book_name,
auth_name,
price
Add_book(),
delete(),
search_name(),
search_author()
Figure: 5. Class Diagram of class Book in Library Information System
Let Ii be the set of all instance variables used by methods Mi and if there n such sets
Let P={(Ii, Ij)|Ii∩Ij=∅}
and Q={(Ii, Ij)|
Ii∩Ij≠ ∅}
If all n sets {Ii},{I2},…..{In} are ∅ then P=∅
LCOM=|P|-|Q|, if |P|>|Q|
=0 otherwise
A positive high value of LCOM implies that classes are less cohesive. Hence, low
value of LCOM is desirable.
Inheritance Metrics
Inheritance Metrics are based on the property of Inheritance of object oriented software.
In Figure 3,
TC=4 (Total Number of Clases)
Let C1 =Person class
C2= Student class
C3= Employee
class C4=Worker
class
Therefore Mi(C1)=0, Mi(C2)=2, Mi(C3)=2,
Mi(C4)=2 and Md(C1)=2, Md(C2)=5,
Md(C3)=5, Md(C4)=4
∑ TC
i=1
Ad(Ci)
AIF =
∑TC Aa(Ci)
i
Where, Aa(𝐶i)= Ai(𝐶i) + Ad(𝐶i)
TC= Total number of classes
Ad(𝐶i)=Number of attributes declared in a class
Ai(𝐶i)=Number of attributes inherited in a class
In Figure
3, TC=4
Let C1 =Person class
C2= Student class
C3= Employee
class C4=Worker
class
Therefore Ai(C1)=0, Ai(C2)=2, Ai(C3)=2,
Ai(C4)=2 and Ad(C1)=4, Ad(C2)=5,
Ad(C3)=8, Ad(C4)=3