Metrics for Object Oriented Software Development
By Samudra Gupta
Introduction
The software development process is no doubt a complicated one.
The end product follows a chain of analysis, design, development
and testing process. At each stage, it is important to follow a
well-defined methodology to ensure a quality end product. For
large scale projects, each stage in the whole process is a
challenge. In this context, the software design and coding
metrics play an important role in ensuring the desired quality.
In this article, we would examine couple of important object
oriented metrics and see how they can be adopted at design and
development stages of a project life cycle to minimize the risk
and improve the software quality.
Why Metrics
In Object Oriented software development process, the system is
viewed as collection of objects. The functionality of the
application is achieved by interaction among these objects in
terms of messages. Whenever, one object depends on another
object to do certain functionality, there is a relationship
between those two classes. In the light of modern day J2EE like
development, it is recommended application software is split
into multiple layers. This ensures "separation of concern". With
this, we have objects from one layer talking to the objects of
another layer.
In order to achieve perfect "separation of concern", objects
should rely on the interfaces and contracts offered by another
object without relying on any underlying implementation details.
For example, the application layer depends on Database Access
Layer to access data. The Application layer however should never
need to know how the data is physically accessed and what the
underlying data store is. This is called abstraction. Thus,
correct level of abstraction helps build a flexible and scalable
application.
All said and done in brief, it is not an easy job to reach the
correct level of abstraction and the correct relationship
between classes. It is better if we can detect any possible
faults at an early stage of the design process, so that the
design can be corrected in accordance. OO Design metrics can be
a very helpful measuring technique to evaluate the design
stability.
Also, given a correct abstraction of layers and appropriate
relationship between the classes, there are still chances that
the coding process might introduce a few more vulnerability.
This vulnerability is not of defective coding as such but more
to do with the internal structure of the code. At this stage
also OO metrics can be of help to identify, if we need to pay
further attention to any of the code to make it more
maintainable.
This is what the role of software design and development metrics
are. They are used to ensure a better quality and
maintainability as a whole. It is also observed that following
these metrics make writing test cases easier. Any application
that can be tested easily is easier to maintain and debug.
Few Object Oriented Metrics
We will now discuss a few Object Oriented Metrics and see on
what context they can be used and what are the benefits of using
these metrics. Cyclomatic Complexity (CC):
Cyclomatic complexity is a measure of the complexity of
algorithms used in a method. It is in essence a count of number
of test cases required to comprehensively test a method. In a
graph, the nodes represent the procedural statements (if/else
etc.) and the edges represent the transition from one node to
the other: then the formula for Cyclomatic Complexity will be:
CC = no of edges – no of nodes+2
Example:
For case 1: The cyclomatic complexity is: 1-2+2 = 1
For case 2: The cyclomatic complexity is : 3-3+2 = 2
The less the complexity, the better it is. More complexity means you have more
decision making and branching going one inside the code block. This makes it
harder to test the method in comprehensive manner.
Wighted Method Per Class (WMC):
This is defined as the sum of the complexity of all the methods defined in a
class. If all the method complexities are reduced to unity (1), then WMC becomes
equal to the number of methods.
WMC = sum of cyclomatic complexities of all the methods.
Following the discussion of Cyclomatic Complexity, a method with high WMC is not
recommended.
Response For Class (RFC):
The RFC is defined as the total number of methods that can be executed in
response to a message to a class. This count includes all the methods available
in the whole class hierarchy. If a class is capable of producing a vast number
of outcomes in response to a message, it makes testing more difficult for all
the possible outcomes.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.