Download
Download
Download
net/publication/2253619
CITATIONS READS
31 4,512
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
GESTO: UM PROCESSO EXPERIMENTAL PARA DETERMINAR O SENTIDO DE UMA OBRA DE ARQUITECTURA View project
All content following this page was uploaded by Fernando Brito e Abreu on 28 December 2012.
2
Criterion 4: metrics should be obtainable early in the • Clustering Factor
life-cycle • Polymorphism Factor
• Method Hiding Factor
Real software systems are usually built by a team of • Attribute Hiding Factor
people. Often is possible to break down the specification • Reuse Factor
in almost independent modules or subsystems. Each team Considering that metrics are intended to quantify the
member or small group of members can be responsible for presence or absence of a certain property or attribute, we
each of those subsystems. Then, we need metrics can view them as probabilities. They would then range
applicable not only to the whole system under considera- from 0 (total absence), to 1 (maximum possible presence).
tion, but also to each one of its modules or subsystems, This perspective was also used in the ESPRIT REBOOT
thus allowing to pin-point "ill-designed" ones. So: project [Stalhane92]. This kind of interpretation allows the
application of statistical theory to software metrics. For
instance, statistically independent metrics can be
Criterion 5: metrics should be down-scaleable
combined (e.g. multiplied) so that the result can still be
interpreted as a probability.
Metrics collection is a repetitive task, therefore tedious
The MOOD metrics definitions are based on a group
and boring for human beings. The worst is that it takes a
of formally defined functions and on set theory and simple
lot of time and money! Provided that criterion 1 is met,
mathematics. This fulfills criteria 1 and 6. All MOOD
and that designs are also formally defined, it is possible to
metrics are expressed as quotients where the numerator is
build some kind of syntactic analyzer that extracts from
the actual use (in the design under consideration) of a
them the needed information for computing the metrics.
given OO abstraction and the denominator is the
The effort to build such a tool is considerable but it is
maximum achievable possible value for the same
worth while. Then:
abstraction use. As a result, all metrics are size
independent and dimensionless and criteria 2 and 3 are
Criterion 6: metrics should be easily computable met. The MOOD metrics meet criterion 4 because they are
applicable as soon as a preliminary system design is
Many specification and programming languages (either available. The proposed metric set can be applied to any
graphical or textual) that support the OO paradigm existent Class Cluster (as defined in section 4.4), or any
abstractions are available in the marketplace. Each of them combination of them, and so we can say that criterion 5 is
has its own constructs that allow for implementation of also fulfilled. No reference is made to specific language
those abstractions in more or less detail. Again, the constructs, that is, MOOD metrics refer to OO abstrac-
requirement of a common base of understanding for the tions, and not to its implementations. Criterion 7 is there-
metrics analysis process, leads us to the need of avoiding fore also accomplished.
the syntactic level. Tools such as those mentioned in the
previous paragraph can guarantee this independence.
Therefore: 4.2 Encapsulation and Information Hiding
Plenty of OO analysis and design methods, as well as
Criterion 7: metrics should be language independent programming languages exist, but often different termi-
nologies are used to refer to the same abstraction with the
Several authors have suggested sets of metrics for the inevitable entanglement of non-experts. The basic OO
OO paradigm; see for instance [Bieman92, Campanai94, concepts are introduced along with metrics definitions in
Chidamber91, Karunanithi93, Yousfi92]. However, most order to help this paper to be as self-explanatory as pos-
of the proposed metrics do not fulfill all the above criteria, sible.
mainly 1, 2, 3 and 7. Objects are an encapsulation of information and be-
havior relative to some entity of the application domain
under consideration (sometimes referred as the UoD -
4. THE MOOD METRICS SET Universe of Discourse). In real systems many objects with
4.1 Introduction similar information (data) and behavior (functionality) can
be found. The class abstraction captures this reality and
The MOOD (Metrics for Object Oriented Design) set can be viewed as an abstract data type. The class
is a collection of metrics that were designed with the definition includes at least two types of features:
above defined criteria in mind. The set includes the fol- attributes (also called variables, fields or data members),
lowing metrics: which stand for the stored information and methods (also
• Method Inheritance Factor called operations, function members, tasks or routines),
• Attribute Inheritance Factor which represent the behavior. All objects created belong to
• Coupling Factor a certain class, so they are often referred as class
3
instances. Within each class all objects share the same 4.3 Inheritance
methods. The object instance variables (i.e. local data) are
Inheritance is a mechanism for expressing similarity
defined in the corresponding class.
among classes. Semantically, it allows the portrayal of
Many features defined in a class are designed for im-
generalization and specialization. As far as design is con-
plementing certain functionalities that are only relative to
cerned, it allows for the simplification of the definition of
the class itself. Those features should be hidden from
inheriting classes. When a class inherits from another, that
client programmers4, not for protection sake but for
means it can use its methods and attributes, unless they are
helping them to cope with complexity, as internal imple-
redefined locally. A class Cd that inherits directly or
mentation details do not (or should not) bring a better
perspective on how to use the services of the class. indirectly from a class Ca is said to be a descendent5 of
Another very important advantage of this information class Ca which, conversely, is called an ancestor6 of class
hiding mechanism is that the use of a class is independent Cd . Now, being more restrictive, a class Cc that inherits
of its implementation, thus allowing to alter it without
directly from a class C p is said to be a child of class C p
"side-effects". As a conclusion, all information about a
class should be private to the class, unless it is specifically which, conversely, is called a parent of class Cc .
declared public. The public part of a class is called its Inheritance can be single or multiple, depending on the
interface and should only be the "tip of the iceberg". The number of parents. The inheritance relation will be
public methods represent the services that the supplier represented here by an arrow, for instance as in
class is able to render to client classes. The hidden part is Cc → C p or Cd → Ca .
called the implementation. The number of methods
The composition of several inheritance relations
defined in class Ci is given by: defines a directed acyclic graph, often called an inheri-
Md (Ci ) = Mv ( Ci ) + Mh ( Ci ) tance hierarchy tree. A base class is the root of such an
where: inheritance hierarchy (i.e. the one that does not inherit;
• Mv ( Ci ) - number of visible methods (interface) in who has no ancestors). Formally we can define the
class Ci function:
• Mh ( Ci ) - number of hidden methods 1 iff ∀j ∈ 1, TC , ¬∃C j : Cb → C j
(implementation) in class Ci is _ base( Cb ) =
0 otherwise
Then we define the Method Hiding Factor: where TC is the total number of classes in the system
under consideration.
∑
TC
Mh (Ci ) A leaf class is a class that has no descendants. For-
MHF = i =1
∑
TC mally, we can define the function:
i =1
Md ( Ci )
1 iff ∀j ∈ 1, TC , ¬∃C j : C j → Cl
Conversely, the number of attributes defined in class is _ leaf ( Cl ) =
0 otherwise
Ci is given by:
In a class hierarchy, each class can have features either
Ad (Ci ) = Av ( Ci ) + Ah ( Ci ) inherited from its ancestors or the locally defined. These
where: latter features can be either new or a redefined version of
Av (Ci ) - number of visible attributes in class Ci inherited ones (overriding situation), or even only declared
Ah (Ci ) - number of hidden attributes in class Ci but not implemented there7. Some approaches even allow
to drop inherited features.
Then we define the Attribute Hiding Factor: For defining the MOOD set of metrics we will need
some basic class metrics. They will be introduced next, by
means of functions where the argument is the class under
∑
TC
Ah (Ci ) consideration and the returned value is the value for the
AHF = i =1
∑
TC corresponding metric. Let Ci be any class of the system
i =1
Ad (Ci )
under consideration. We define:
4
• Children Count, CC ( Ci ) - number of children of
Ci (note: if CC ( Ci ) = 0 then Ci is a leaf class) • Total number of Methods Inherited,
TMi = ∑k=1 Mi (Ck ) = ∑k=1 Mn (Ck )* DCC
TC TC
• Descendants Count, DC (Ci ) - number of ( k ) − Mo (Ck )
descendants of Ci
= ∑k=1 Md (Ck ) − Mo (Ck ) * DCC
TC
( k ) − Mo (Ck )
• Parents Count, PC( Ci ) - number of parents of Ci
(notes: if PC( Ci ) =0 then Ci is a base class; if
• Total number of Methods Available,
PC( Ci ) >1 we have multiple inheritance).
TMa = TMd + TMi = ∑k =1 Ma (Ck )
TC
Md (Ci ) = Mn ( Ci ) + Mo (Ci )
TMa = TMd + TMi = ∑ k =1 Ma ( Ck )
TC
Ma ( Ci ) = Md (Ci ) + Mi ( Ci )
= ∑k =1 Mn ( Ck ) * 1 + DC( Ck )
TC
= Mn (Ci ) + ∑ j =1
PC (Ci )
Ma ( C j )
where Ci → C j = ∑k =1 Md (Ck ) * 1 + DC( Ck )
TC
designation10.
Some system metrics are now defined, based on the
above ones. The demonstration of some expressions is not • Total Number of Inheritance Paths, (total number of
included here because they are either trivial or beyond the inheritance paths from a base class to a leaf class),
scope of this paper.
TNIP =
• Total number of Methods Defined, TLIC − TC − ∑i =1 is _ base(Ci ) + is _ leaf (Ci )
TC
• Total number of Methods Overridden, Note: MIF=0 means that there is no effective inheri-
TMo = ∑k =1 Mo (Ck )
TC
tance (i.e. there are no inheritance hierarchies or all
inherited methods are overridden).
8 - "New" denotes those methods that are not overriding inherited ones. Similarly, we can also define the Attribute Inheritance
9 - "Available" stands for those methods that can be invoked in Factor given by:
association with the class under consideration (i.e. those defined in that
class as well as the inherited ones).
10 - This situation is generally referred as "name clashing".
5
TAi reuse because they do not need to drag along anything
AIF = else. We shall name them Class Clusters and the shape of
TAa each one will be of a single or several intercommunicating
inheritance hierarchy trees. For a total number of Class
where TAi and TAa have definitions similar to TMi and Clusters, TCC, we define the Clustering Factor:
TMa .
TCC
CLF =
4.4 Coupling and Clustering TC
A class Cc is called a client of class Cs , and Cs a
4.5 Polymorphism
supplier11 of class Cc , whenever Cc contains at least one
reference to a feature (method or attribute) of class Cs . Polymorphism is a greek originated word that means
"many forms". When applied to Object-Orientation, it
We will represent this client-supplier relation by
stands for the possibility of sending a message without
Cc ⇒ Cs . knowing which will be the form (class) of the object that
Some of these client-supplier relations can be viewed will bind that message to one of its interface methods. All
as communications between class instances. These the potential receiving classes belong to the same inheri-
communications should be made explicit for the sake of tance hierarchy tree. Binding can be static (at compilation
understandability. Some approaches use the designations time) or dynamic13 (at run time).
message, event or stimulus, to refer to the call that an Messages can be bound to instances of a certain class
instance of the client class does to a supplier class method. or to instances of one of its descendants and not the other
It is desirable that classes communicate with as few others way around. Consider for instance that the class ball is
as possible and even then, that they exchange as little specialized by classes tennis_ball, golf_ball, soccer_ball
information as possible [Meyer88]. and rugby_ball. If by sending the message ball.new (call
Supplier class references are not only made by means of constructor method), we get a tennis_ball or a
of messages. A supplier class type reference can be made golf_ball, everything is fine. However, if the message
inside client classes in situations such as: soccer_ball.new is sent, getting some instance of class ball
• a public or private global attribute (some languages is not acceptable as it might consist, for example, of a
only allow global attributes to be private) rugby_ball.
• a public or private method argument or local attribute If there is no overriding, a message to a class or to one
A bigger number of client-supplier relations increase of its descendants will be bound to the same method (i.e.
complexity, reduces encapsulation and potential reuse, and no polymorphism). Conversely, we will obtain the
limits understandability and maintainability. possible maximum polymorphism potential if all methods
Every class in a certain system is a potential supplier of are overridden in all classes (except the base ones, of
all other classes and vice-versa. Thus, the maximum value course). In fact, if a method M in class Ci , is overridden
of client-supplier relations12 is given by TC − TC . If
2
in all descendants of class Ci , then a message bound to M
we consider the following function:
can have DC (Ci ) possible addressees other than the
1 iff Cc ⇒ Cs ∧ Cc ≠ Cs implementation of M in class Ci . Those correspond to the
is _ client ( Cc , Cs ) = same amount of different implementations of M in Ci
0 otherwise
then, the Coupling Factor is given by: descendants (polymorphic situations). Extending this
reasoning to whole methods in the whole system, the
maximum number of possible different polymorphic
∑ ∑
TC TC
i =1 j =1
is _ client (Ci , C j ) situations is given by:
COF =
TC 2 − TC
∑
TC
i =1
Md (Ci ) * DC( Ci )
The "web" defined by client-supplier and inheritance
relations is, in real systems, a set of disjoined graphs For a given system, however, the total number of
where nodes represent classes and edges represent the possible different polymorphic situations is:
relations. Each of these graphs is a potential cluster for
∑ ∑
TC DC ( Ci )
i =1 j =1
Mo ( C j )
11 - Note that a class can be client (and therefore supplier) of itself.
12 - Here we have not considered the "harmless" reflexive client-supplier
situations, that is, a class being supplier of itself. 13 - Also called late or delayed binding.
6
Note: the inner sum refers to the descendants of Ci 1 iif Ci ∈ L
in _ library( Ci ) =
0 otherwise
Finally we define the Polymorphism Factor:
L = {classes in the reusable class library}
∑ ∑ M (C )
TC DC(Ci )
i =1 j =1 o j 5. DESIGN HEURISTICS
PF =
∑ M (C ) * DC(C )
TC
d i i By thorough interpretation of data taken from real
i =1
projects, we believe that we will be able to compute
design heuristics. Those can exhibit three shapes:
4.6 Reuse recommended lower limit (LL), recommended interval
(INT) and recommended upper limit (UL). Table 1 shows
Reuse, enforced by the OO paradigm abstractions, is
which shape applies for each of the MOOD metrics. The
expected to produce big impacts on development produc-
appropriateness of each limit (including the interval ones)
tivity and quality. It apparently14 saves a lot of develop- is expected to increase as our metrics collection and
ment time, thus reducing system costs or allowing savings analysis process proceed.
to be spent on building more functionality, quality
assurance or other activities. Reusable components are
MOOD METRIC LL INT UL
usually more carefully designed than ordinary program
code. Besides, its repeated use brings out quickly any Method Inheritance Factor x
flaws in its design or implementation. That is why those Attribute Inheritance Factor x
components tend to be of better quality, therefore Coupling Factor x
embedding that quality in systems who incorporate them. Clustering Factor x
Reuse in OO software development can mainly take Polymorphism Factor x
two shapes: reuse of library components and reuse by Method Hiding Factor x
means of inheritance. Then, we can consider three types Attribute Hiding Factor x
of classes in a given system: (i) those base classes built Reuse Factor x
totally new, (ii) those extracted from a library and finally
(iii) those that reuse existing classes by means of inheri- Table 1: Shape of design heuristics based on MOOD
tance. As stated in the inheritance section above, inherited
class definitions are usually specialized either by According to this framework, expected recommenda-
extending its features or by redefining ("overriding") tions will be of the kind:
them. This specialization effort, together with that of
building classes "from scratch" corresponds to the effec- • "Keep the Method Inheritance Factor between 0.25
tive "new" part of the system under consideration. We and 0.37"
want to quantify exactly the other part, that is, the one • "Coupling Factor should be below 0.52"
corresponding to used library classes and the fraction of • "Good Reuse Factors are those above 0.43"
all others that may be imputed to inheritance. For this Values mentioned above are irrelevant. We expect to
fraction calculation, we will only consider methods, as disclose some realistic ones in a following paper.
those are much more expensive to build and maintain than
attributes. Now we can define the Reuse Factor as:
6. FUTURE WORK
∑
TC
in _ library(Ci ) We are presently developing a tool for supporting the
RF = i =1
+ collection, storage and analysis of the MOOD metrics set.
TC The core of this tool (metrics definition dictionary, metrics
MIF * ∑i =1 1 − in _ library(Ci )
TC storage, human-machine interface) is language
+ independent. Specific implementation language stubs will
TC parse the specification code and determine the base
measure function values. The C++ stub is under
where construction and we plan to develop an Eiffel [Meyer92]
one in the near future. When the tool becomes fully
operational, we will proceed to an extensive evaluation of
available systems and try to derive and refine the values
for the limits mentioned in the design recommendations.
14 - We can not downplay the effort of searching, and eventually The study of correlation between MOOD metrics and
adapting, reusable components from the class library, as well as the quality attributes as those mentioned in [ISO9126] will be
effort of building, validating and maintaining it.
7
one of next steps. We will also investigate the statistical [Bieman92] Bieman J., "Deriving Measures of
independence of each MOOD metric towards each of the Software Reuse in Object Oriented Systems", Proceedings
other ones. of The BCS-FACS Workshop on Formal Aspects of
We think that the MOOD metrics (except the Reuse Measurement, Springer-Verlag, 1992.
Factor) can be combined to obtain a generic OO software
[Campanai94] Campanai M. and Nesi P., "Supporting
system complexity metric. That is one of our future chal-
O-O Design with Metrics", Proceedings of TOOLS
lenges. We will start by evaluating the MOOD metrics
Europe'94, France, 1994.
against a set of desiderata for software complexity metrics
defined in [Weyuker88]. [Chidamber91] Chidamber S. and Kemerer C.,
A concurrent effort for developing a resource estima- "Towards a Metrics Suite for Object Oriented Design",
tion model named MOORED (Model for Object Oriented Proceedings of OOPSLA'91, pp.197-211, 1991.
Resource Estimation Determination) is under way, and
[Dreger89] Dreger J.B., Function Point Analysis,
some cross-fertilization is expected in the field of com-
Prentice-Hall, Englewood Cliffs, NJ,1989
plexity and productivity evaluation.
[ISO9000-3] ISO/IEC 9000 Part 3, Guidelines for the
Application of ISO 9001 to the Development, Supply and
7. CONCLUSIONS
Maintenance of Software, 1991.
The adoption of the Object-Oriented paradigm is ex-
[ISO9126] ISO/IEC 9126, Information Technology
pected to help produce better and cheaper software. The
- Software Product Evaluation - Quality Characteristics
main concepts of this paradigm, namely, inheritance,
and Guidelines for their use, 1991.
encapsulation, information hiding or polymorphism, are
the keys to foster reuse and achieve easier maintainability. [Jacobson92] Jacobson I., Christerson M., Jonsson P.
However, the use of constructs that support those concepts and Övergaard G., Object-Oriented Software Engineering
can be more or less intensive, mainly depending on the - A Use Case Driven Approach, ACM Press / Addison-
designer ability. Advances in quality and productivity Wesley, 1992.
need to be correlated with the use of those constructs.
[Karunanithi93] Karunanithi S. and Bieman J.,
Therefore, we need to evaluate them quantitatively to
"Candidate Reuse Metrics For Object Oriented and Ada
guide OO design. The availability of these metrics should
Software," Proceedings of IEEE International Software
allow comparison of different systems or different
Metrics Symposium, pp.120-128, May 1993.
implementations of the same system, thus helping to
derive some design heuristics that could/should be [Meyer88] Meyer B., Object-oriented Software
included in design tools. Those heuristics would at least be Construction, Prentice Hall International, 1988.
a valuable help to new staff members.
[Meyer92] Meyer B., Eiffel: The Language,
"Blind" choice (or creation) is dangerous, so a set of
Prentice Hall International, 1992.
common requirements for metrics and corresponding
rationale was introduced, which includes the need for [Stalhane92] Stalhane T. and Coscolluela A., "Final
formal definition, language independence, dimension- Report on Metrics", Deliverable D1.4.B1, ESPRIT Project
lessness, ease of calculation and early obtainability. A 5327 (REBOOT), February 1992.
suitable metrics set named MOOD was then proposed. We
[Symons91] Symons C.R., Software Sizing and
believe that these metrics can help in setting OO design
Estimating - Mk II Function Point Analysis, John Wiley &
standards at the organization level, helping OO
Sons, 1991.
practitioners to guide their development process and,
hopefully, leaving them in a cheerful MOOD... [Weyuker88] Weyuker E., "Evaluating Software Com-
plexity Metrics", IEEE TSE, vol.14, n.9, pp.1357-1365,
September 1988.
REFERENCES
[Yousfi92] Yousfi N., "Measuring Internal
[Abreu93] Abreu F.B., "Metrics for Object Ori- Attributes of Object-Oriented Software Products", Pro-
ented Software Development", Proceedings of 3rd Inter- ceedings of the 5th Int. Conference on Software Engi-
national Conference on Software Quality, ASQC, Lake neering & its Applications, Toulouse, 1992.
Tahoe, USA, October 1993.
[Zuse91] Zuse H., Software Complexity: Mea-
[Albrecht83] Albrecht A.J. and Gaffney J.E., sures and Methods, Walter de Gruyer, 1991.
"Software Function, Source Lines of Code and Develop-
ment Effort Prediction", IEEE TSE, vol.9, n.6, pp.639-
648, November 1983.