CHIDAMBER AND KEMERER:
A
METRICS
SUITE
FOR
OBJECT
ORIENTED DESIGN
419
inherently. An observer can assign features to an individual,
but these are attributes and not properties. All substantial
individuals possess a finite set of properties; as Bunge notes,
“there are no bare individuals except in our imagination” [5].
Some of the attributes of an individual will reflect its
properties. Indeed, properties are recognized only through
attributes. A known property must have at least one attribute
representing it. Properties do not exist on their own, but are
“attached” to individuals.
On
the other hand, individuals are
not simply bundles of properties. A substantial individual
and its properties collectively constitute an
object
[42], [43].
Therefore, an object is not simply a bundle of methods,
but a representation of the application domain that includes
the methods and instance variables that a designer assigns
to that object. Another benefit of this stream of research is
that it provides a formal mathematical approach to dealing
specifically with the key ideas of object orientation.
An object can be represented in the following manner:
X
=
(~,p(z))
where
z
is the substantial iniividual and
p(z)
is the finite collection of its properties.
:I:
can be considered to be the token
or
name by which
the object is represented in a system.
In
object oriented
terminology, the instance variables’ together with its methods4
are the properties of the object
[l].
Using these representations of objects, previous research has
defined concepts like scope and similarity that are relevant to
object oriented systems [5], [42]. Following this tradition, this
paper defines in the paragraphs below two important software
design concepts for object classes, coupling and cohesion.
Intuitively, coupling refers to the degree of interdependence
between parts of a design, while cohesion refers to the internal
consistency within parts of the design. All other things being
equal, good software design practice calls for minimizing
coupling and maximizing cohesiveness. It should be noted that
these definitions are derived from the ontology of objects as
opposed to other sources that have been graph-theory (e.g.,
McCabe [29]), information content (e.g., Halstead
[
171) or
structural attributes (e.g., Card and Agresti [7]).
For
further
details on the appropriateness of the ontological approach the
reader is referred to the comprehensive treatment of the subject
in [42], [321 and [391.
Coupling
In
ontological terms, “two objects are coupled if
and only if at least one of them acts upon the other,
X
is said
to act upon
Y
if the history of
Y
is affected by
X,
where
history is defined as the chronologically ordered states that a
thing traverses in time” [41, p. 5471.
Let
X
=
(z,p(z))
and
E’
=
(y,p(y))
be two objects.
‘An instance variable stores a unique value in each instance
of
a
class
4A
method is an operation on an object that
is
defined as part
of
the
declaration
of
the class.
where
{M,}
is the set of methods and
{It}
is the set of instance
variables of object
i.
Using the above definition of coupling, any action by
{M-y}
on
{My}
or
{ly}
constitutes coupling, as does any action by
{My}
on
{M*y}
or
{I-y}.
When
A4-y
calls
My,
Mdy
alters
the history of the usage of
My;
similarly when
May
uses
I,,
it alters the access and usage history of
11,.
Therefore, any
evidence of a method of one object using methods or instance
variables of another object constitutes coupling. Since objects
of the same class have the same properties, two classes are
coupled when methods declared in one class use methods
or
instance variables of the other class.5
Cohesion
Bunge defines
similarity
IT()
of two things to be the
intersection of the sets of properties of the two things [5, p 871:
Following this general principle of defining similarity in terms
of sets, the degree of similarity of the methods within the
object can be defined
to
be the intersection of the sets of
instance variables that are used by the methods. This is an
extension of Bunge’s definition of similarity to similarity of
methods. It should be clearly understood that instance variables
are not properties of methods, but it is consistent with the
notion that methods of an object are intimately connected to
its instance variables.
where
u(M1.
M2)
=
degree of similarity of methods
MI
and
Mz
and
{Ii}
=
set of instance variables used by method
M,.
Example:
Let
{II}
=
{a,b,c,d,e}
and
(12)
=
{n,b,e}.
(11)
n
{I2}
is nonempty, and
CT(MI,M~)
=
{a,b,e}.
The degree of similarity of methods relates both to the
conventional notion of cohesion in software engineering, (i.e.,
keeping related things together) as well as encapsulation, that
is, the bundling of methods and instance variables in an object
class. The
degree
of
similarity
of methods can be viewed as
a major aspect of object class cohesiveness. If an object class
has different methods performing different operations on the
same set of instance variables, the class is cohesive. This view
of cohesion is centered
on
data that is encapsulated within an
object and
on
how methods interact with data. It is proposed
for object orientation as an alternative to other previous
approaches, such as generalization-specialization cohesion or
service cohesion as defined by Coad and Yourdon
[
111.
Complexity
of
an Object:
Bunge defines complexity of an
individual to be the “numerosity of its composition”, implying
that a complex individual has a large number
of
properties
(51. Using this definition as a base, the complexity of an object
class can be defined to be the cardinality of its set of properties.
Complexity of
(z,p(z))
=
lp(z)I,
where
lp(z)I
is the cardi-
nality
of
p(z).
Scope
of
Properties:
In
simple terms, a class
is
a set of
objects that have common properties (i.e., methods and in-
stance variables). A designer develops an abstraction of the
’
Note that this will include coupling due to inheritance.