Cognitive Weighted Response For A Class: A New Metric For Measuring Cognitive Complexity of OO Systems

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Cognitive Weighted Response For a Class: A

New Metric for Measuring Cognitive


Complexity of OO Systems

Abstract –Various new techniques, methods and metrics are being developed by researchers for
calculating the complexity of the class in Object Oriented (OO) software. Chindamber and
Kemerer (CK) have proposed a metric suite for measuring the class complexity of OO design. CK
metrics are well known and widely accepted suites of OO metrics. Among those set of metrics,
Response For a Class (RFC) is one of the metric which is nothing but the number of methods that
can be potentially executed in response to a message received by an object of a class. In RFC, each
function call statement value is considered to be 1. The cognitive feature is not included in RFC
metric which felt major negative aspect of this metric. So here, we are proposing a new metric
namely Cognitive Weighted Response For a Class (CWRFC). In CWRFC, the cognitive weights
have to be assigned for the function call statement based on the effort needed to understand their
type of function calls due to message passed by an object of that class. The proposed metric has
been proved to be a better measure of cognitive complexity of class with function call statement
through the case studies and experiments.

Keywords: CK metric, Cognitive Weight, Software Complexity, Cognitive Weighted Response


For a Class, Response For a Class, Function Call, Message Passing.

4.1 INTRODUCTION
Since, the complexities of software systems are more famous now than ever the
challenges to a software engineer are to somehow understand and manage such large systems
and deal with software cognitive complexities [9]. Cognitive informatics is a trans-disciplinary
enquiry of cognitive and information sciences that investigates the internal information
processing mechanisms and processes of the brain and natural intelligence, and their engineering
applications via an interdisciplinary approach [42]. Software complexity deals with the
Psychological complexity of the programs [23]. It measures serve both as an analyzer and a
predictor in quantitative software engineering [5]. Identification of complex modules is very
important as they require exact testing so as to develop a better quality software system.
Additionally, this identification may help during maintenance. Source code metrics can be used
to locate such modules. Object-oriented technologies have been increasingly used in
organizations these days. It is theorized that structural properties such as coupling, cohesion,
functional complexity and inheritance have an impact on the cognitive complexity of the system
[11]. That is, it places a “mental burden” on developers, inspectors, testers and maintainers to
understand the system [42].
Software metrics play a vital role in the software industry to assure the quality of the
software. Though the reusability function of Object Oriented Paradigm has enriched the
capability of several software industries, it has considerably increased the complexity [26]. So,
there is a need for introducing new complexity measures. A new metric namely Cognitive
Weighted Response For a Class (CWRFC) is proposed for an OO systems which is an extension
of the Response For a Class (RFC) proposed Chindamber and Kemerer (CK) [8]. CWRFC
includes the cognitive complexity due to message passing by an object to the Function Call
Statement (FCS) and is a better indicator of complexity of OO systems.
Calling the function is an indispensable part of an OO programming language. Function
is called by its name and the message may be passed through the list of arguments. Based on the
message passing, the FCS is divided into two categories such as Default Function Call Statement
(DFCS) and Argumentum Function Call Statement (AFCS). Commonly messages are passed in
two ways. They are Pass By Value (PBV) and Pass By Reference (PBR). It is proven that an
AFCS may be represented as the combination of PBV and PBR. In PBV, values are passed from
actual arguments of a calling function to formal arguments of a called function. In PBR,
addresses are passed from actual arguments of a calling function to formal arguments of a called
function. It is known that, in PBR the changes made in the called function will be reflected in the
calling function, where as in PBV the changes will not be reflected.
With respect to many cognitive processes, the Cognitive complexity of a computer
program can be studied. Program comprehension is one of the important cognitive processes
involved in programming. In this paper, a new metric CWRFC is defined and validated against
the comprehension process.
4.2 LITERATURE REVIEW
Several metrics have been proposed for OO systems by researchers. A metric suite
proposed by Chindamber and Kemerer (C&K) is one of the best known suites of OO metrics.
The six metrics proposed by CK are Weighted Method per Class (WMC), Depth of Inheritance
Tree (DIT), Response For Class (RFC), Number Of Children (NOC), Lack of Cohesion of
Methods (LOCM) and Coupling Between Objects (CBO)[21,8]. Parvinder Singh Sandhu and Dr.
Hardeep Singh [6] have proposed a paper that gives the evaluation of CK suit of metrics and
suggests the refinements and extensions to these metrics so that these metrics should
reflect accurate and precise results for OO based systems. Raed Shatnawi [24] has proposed
a paper that identifies the threshold values for CBO, RFC and WMC at two levels of risks using
a quantitative methodology based on the logistic regression curve. These threshold values can be
used to identify the most error-prone classes.
Classes are the building blocks of any object oriented program. Class is an encapsulation
of attributes and functions (function are known as methods). Functions are the self contained
block of statement that performs some kind of task. It reduces the complexity and debugging of
the larger programming by dividing them into smaller functions. It is clear that the function is
one of the major factors which will affect the complexity of the class and the use of different
type of function call statement will increase the complexity of the programs. There are no
Specific measures that exist to calculate the complexity arising due to cognitive load in
understanding the different FCS. Hence, a new metric [CWRFC] has been proposed for object
oriented system with an internal architecture of an object.
Section organization of this chapter is as follows, the proposed metric CWRFC is
explained in section 4.3, Calibration of FCS is discussed in section 4.4, the experimentation of a
new metric and the case study is described in section 4.5, a comparative study of CWRFC with
RFC in section 4.6 and Section 4.7 presents the conclusion and future work.

4.3 PROPOSED METRIC: COGNITIVE WEIGHTED RESPONSE FOR a CLASS


(CWRFC)
CWRFC is used to calculate the complexity of the class using the Response Set
complexity. If there are m numbers of response sets in a class then, the CWRFC of that class can
be calculated using the Equation (1).
m
CWRFC=∑ RSC j (1)
j=1
Where
RSC is the response set complexity, which can be calculated by adding, the set of all
methods (M) in a class and set of methods (R) called by any of those methods.
RSC =M + ∀i Ri (2)
Based on the message passing, the Methods are divided into two categories such as
Method With Argument (MWA) and Method without Argument (MOA). MOA is also known as
Default Function (DF). Commonly in MWA, the arguments are passed in two ways. They are
Pass By Value (PBV) and Pass By Reference (PBR). So RSC can be calculated by using the
Equation (3).
R=DF∗( C W f +WF d ) + PBV ∗( CW f +WF v ) + PBR∗( CW f +WF r ) (3)
Where
DF is the total number of Default Function Call Statements
PBV is the total number of Pass By Value Function Call Statements
PBR is the total number of Pass By Reference Function Call Statements
CWf is the Cognitive Weights of the Function Call Statement
WFd is the Weighting Factor of the DFC statements
WFv is the Weighting Factor of the PBV statements
WFr is the Weighting Factor of the PBR statements

Wang et.al, [45] has proposed cognitive weights of the control structure in a method as 1,
2, 3, and 4 to the sequence, branch, iteration and function call statement respectively. J.Charles
et. al [1] has also validated the weights proposed by Wang. Therefore, the cognitive weight of
the Function Call Statement holds the value as 2 by Wang [45].
The weighting factor of different type of the FC statement is based on the classification of
cognitive phenomenon as described by Wang[49], is as follows
Weights
Sub-Conscious Cognitive Function Call Statement (DF) 1

Meta Cognitive Function Call Statement ( PBV) 2

Higher Cognitive Function Call Statement (PBR) 3


4.4 CALIBRATION
In this chapter, we validate Default Function, Pass By Value and Pass By
Reference as Sub, Meta and Higher Cognitive Function Call Statement respectively. A
comprehension test has been conducted for a group of students to find out the time taken to
understand complexity of object oriented program with respect to the function call. The group of
students selected had sufficient exposure in analyzing the object oriented programs, as they had
undergone courses in C++ language. 30 students who scored 65% and above marks in the
semester Examination were selected to participate in the comprehension test.
The time taken by students to comprehend the programs was recorded after the
completion of each program, as shown in Fig.4.1 All these program comprehension timings were
registered and the mean time to comprehend was calculated. As three different programs have
been administered in each case, totally nine different mean timings were recorded. Average time
was calculated for each program from the individual time taken by students.
350
300 Program 1
Program 2
250
Program 3
200 Program 4
150 Program 5
100 Program 6
50 Program 7
Program 8
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Program
28 29 309

Fig.4.1 The individual time taken by the student to solve programs.

300

250

200

150
Programs
100

50

0
1 2 3 4 5 6 7 8 9

Fig.4.2 The average time of each program from the test conducted on the students.
TABLE 4.1
AVERAGE TIME OF AN EACH PROGRAM AND ITS CATEGORY
Programs Average Time Category Average Time
1 227.4483
2 170.1379 PBR 179.1494
3 139.8621
4 133.4483
5 137.7241 PBV 142.2299
6 155.5172
7 129.1724
8 79.86207 DF 104.9655
9 105.8621

In the Table 4.1, the average comprehension time of programs is listed. These programs
are based on object oriented programs. The mean times are also calculated for each category of
the programs and are tabulated. From the table, it’s clear that, the mean time of PBR is higher
than PBV which in turn is higher than DF. That implies the cognitive load to understand the PBR
is greater than PBV and DF. So here, we conclude that PBR, PBV and DF belong to Higher,
Meta and Sub Cognitive Function Call respectively. The graphical representation of Fig.4.3
gives a better understanding of the complexity of PBR, PBV and DF.

DFC
24%

PBR
43%

PBV
33%

Fig.4.3 Graphical representation of each category.


4.5 EXPERIMENTATION AND A CASE STUDY
The proposed complexity metric given by equation 1 is evaluated with the following
example program namely PROGRAM 4.1. The pictorial representation of PROGRAM 4.1 is
shown in Fig 4.4
PROGRAM 4. 1(with both the types FCS):
#include <iostream.h>
using namespace std;
class student 
{
protected:
  int roll_number;
public:
  void get_number(int a) 

roll_number=a ;  
  }
  void put_number(void) 

     cout << "Roll No: " << roll_number << endl; 
  }
};
class test : public student
{
protected:
  float part1,part2;
public:
  void get_mark(float &x, float &y)
 { 
     part1=x;
part2=y;
  } 
  void put_mark(void)

cout << "Marks obtained: "  << endl;
     cout << "Part1: "  << part1 << endl;
     cout << "Part2 "  << part2 << endl; 
  }
};
class sports 
{
protected:
  float  score;
public:
  void get_score(float s) 

     score = s;  
  }
  void put_score(void) 

     cout << "Score wt: " << score << endl; 
  }
};
class  result : public test, public sports 
{
   float  total;             
public:
void calculate(void)
{
total = part1 + part2 + score;
void grade(total);
}
void grade(float &tot)
{
total1=tol;
if(total1>=40)
cout<< "Pass " <<endl;
else
cout<< "Fail " <<endl;
}
  void display(void); 
};
void result :: display(void)
{
put_number();
put_mark();
put_score();
}
int main()
{
   result student1;
   student1.get_number(110); //RS1
   student1.get_mark(27.5,30.0); //RS2
   student1.get_score(6.0); //RS3
student1.calculate(); //RS4
   student1.display(); //RS5
return 0;
}
Fig.4.4 An example of an object oriented system with FCS
Measurement:
In the above program, the number of response set is 5. They are denoted as RS1, RS2,
RS3, RS4 and RS5. The complexity measurement of these response sets value are as follows.,
RSC =M + ∀i Ri
R=DF∗( 2+1 ) + PBV ∗( 2+2 ) + PBR∗( 2+3 )
R=DF∗( 3 )+ PBV ∗( 4 ) + PBR∗ (5 )
Calculation for RSC1
M =1
R = 0*(3)+0*(4)+0*(5) = 0
RSC1 = 1+0 = 1

Calculation for RSC2


M =1
R = 0*(3)+0*(4)+0*(5) = 0
RSC2 = 1+0 = 1
Calculation for RSC3
M =1
R = 0*(3)+0*(4)+0*(5) = 0
RSC3 = 1+0 = 1

Calculation for RSC4


M =1
R = 0*(3)+0*(4)+1*(5) = 5
RSC4 = 1+5 = 6

Calculation for RSC5


M =1
R = 3*(3)+0*(4)+0*(5) = 9
RSC1 = 1+9 = 10

Value of CWRFC
m
CWRFC=∑ RSC j
j=1

Here m=5
CWRFC=RSC 1+ RSC 2+ RSC 3+ RSC 4 + RSC 5
= 1+1+1+6+10
= 19
4.6 COMPARISON WITH OTHER MEASURES
A comparative study has been made with most widely accepted CK metric suite [8] and
found that RFC metrics proposed by CK et.al didn’t provides the total complexity of the class by
considering the cognitive complexity due to message passed by an object to the function call of
that class. This differentiates our metric from the CK metrics. Mishra et.al suggested that one can
calculate the complexity of the class by using cognitive weights of the basic control structure
such as sequence, branch, iteration and call structures. The current CWRFC metric is one step
ahead of CK’s RFC, because it includes the complexity that arises due to the different types of
function call statement and internal architecture of an object which passes the message to the
functions. Another advantage of our metric is that, it takes cognitive weights into consideration.
In the following Table 4.2, a comparison has been demonstrated with RFC and CWRFC.
We calculated the weight of the class by calculating the response set complexity, in terms
of Default Function Call Complexity (DFCC) and Argumentum Function Call Complexity
(AFCC). This is better indicator than the CK’s RFC. The weight of each function call statement
is calculated by using cognitive weights and weighting factor of type of the message passed to
the function call statement by an object which is suggested by Chidamber et al and Wang. We
found that the resulting value of CWRFC is higher than the RFC. This is because, in RFC, the
weight of each calling statement is assumed to be one. However, including cognitive weights for
calculation of the RSC is more realistic because it provides for the complexity of the internal
architecture of an object. The results are shown in the Table 3 itself.

TABLE 4.2

COMPARISON OF CWRFC WITH RFC


Metrics

RFC CWRFC

Programs
1 9 19
2 10 29
3 5 17

The RFC and CWRFC values were compared and found that CWRFC measure was
larger. According to Chindamber et.al, RFC is an enhanced indicator of complexity of the class.
From the table 3, it is observed that CWRFC value is larger than RFC value which concludes
that CWRFC is a better indicator of complexity of the classes with function call statement
because of the consideration of response set complexity.

4.7 CONCLUSION AND FUTURE WORK


A Cognitive Weighted Response For a Class (CWRFC) metric for measuring the class
level complexity has been formulated. The complexity of the class includes the internal
complexity of the class and the response set complexity. CWRFC includes the cognitive
complexity due to internal architecture of an object, which passes a message to the functions.
CWRFC has proven that, complexity of the class getting affected, which is based on the
cognitive weights of the different FCS. The metric is evaluated through a case study and a
comparative study, and proved to be a better indicator of the class level complexity. The
proposed metric focuses only on the first level class data. Further, it may be evaluated with the
special types of FCS like passing object by reference, object as value, an array of structure to
functions, recursive function call and so on., A tool is to be developed for calculating the
CWRFC value and to compare it with other metrics. Newer metrics may also be proposed and
validated for assessing the cognitive complexity of other object oriented features.

You might also like