Keywords

1 Introduction

Software reusability is an imperative requirement for cost and time optimized software development. Inheritance is considered as one of the most vital features of OO paradigm which has great impact on software reusability. Intricacy of inheritance hierarchy greatly affects the reusability as well as maintainability of system so it is important for designers to know about the complexity of inheritance hierarchy. Inheritance metrics actually provides information regarding complexity of inheritance that’s why we are focusing on inheritance metrics with respect to software reusability here [13, 15]. Research work in [8] also focuses on fruitfulness of reuse as it emphasize on pattern’s analysis like a way to assist the reuse of software knowledge by confining conceptual models in those domains. Reuse of software through inheritance fabricates more comprehensible, maintainable and trustworthy software [2]. Research work in [3, 6, 7] specifies that if a system is not utilizing inheritance then that would be better in maintainability as compared with a system utilizing inheritance.

Nevertheless, this fact is approved that deeper inheritance hierarchy leads to better reusability and harder maintainability of the system. So designers possibly will be liable to maintain the inheritance hierarchy trivial, dumping reusability through inheritance for the ease of comprehension [5]. Thus it is essential to determine the intricacy of inheritance hierarchy for the purpose of determining the discrepancies between the shallowness and depth of inheritance hierarchy. In this paper we consider the inheritance metrics presented in [10] and [11] for comparison as these metrics give information about class inheritance hierarchy and reusability in much comprehensible way. During their study we came to know that these metrics give information about complexity of inheritance hierarchy in terms of subclasses/children but what will be intricacy of inheritance hierarchy w.r.t. parent classes/super classes which in turn helps us in determining the reusability. So in order to explore this phenomenon we have proposed our own inheritance metrics.

Rest of the paper is organized is as follows. Section 2 shows related work and Sect. 3 presents proposed metric suite of inheritance. In Sect. 4 there are two examples of inheritance trees and their calculations to illustrate existing and proposed metrics. Section 5 presents results of existing and proposed inheritance metrics and Sect. 6 explains analysis of results of existing and proposed inheritance metrics. Section 7 presents conclusion and future works respectively.

2 Related Work

Software metrics have indispensable role in the field of software engineering for the purpose of determining and approximating software quality, complexity, reusability, cost and project exertion etc. Here we will give brief overview of OO based metrics proposed by researchers and then we give emphasis of inheritance metrics.

In Existing Object Oriented Metrics several OO based metrics have been proposed till now for the measurement and illustration of different aspects of OO paradigm e.g. cohesion, inheritance and encapsulation etc. Metrics suite proposed in [4, 5] is one of the best known OO metrics suite relating to inheritance, cohesion and coupling etc. There are five metrics defined for measuring a component’s comprehension, adaptability and portability with confidence intervals [14]. Another set of metrics is considered suitable for evaluating the use of the main abstractions of the OO paradigm such as inheritance, encapsulation, information hiding or polymorphism [1]. Authors [9] have surveyed metrics proposed for OO systems and mainly focused on product metrics that can be applied to an advanced design. Inheritance metrics proposed in described the inheritance of inheritance tree in OOD as Average Degree of Understand-ability (AU) and Average Degree of Modifiability (AM) [12].

In Existing Inheritance Metrics, there are number of authors who have proposed different inheritance metrics but here we consider inheritance metrics of [10, 11] as these metrics give information about class inheritance hierarchy and reusability in much comprehensible and graspable way.

In Average Inheritance Depth (AID) Metrics, it is suggested in [10] that AID metric is the mean depth of inheritance tree and this is an extension of [4, 5]’s DIT (Depth of Inheritance tree) metric. The AID of a class is calculated by [11] as:

$$ {\text{AID }} = \, \sum \left( {\text{Depth of each class}} \right)/Number\,of\,Classes $$
(1)

This metric AID is actually the ratio of sum of depth of each class in class inheritance tree to the total number of classes in that inheritance tree. Different inheritance metrics are presented in [10] as DBRM, ANDC and ANIC.

Derived Base Ratio (DBR).

Metric is the ratio of the total derived classes to the total base classes in the class inheritance Tree [10]. DBRM is calculated as follows:

$$ {\text{DBRM }} = \, \sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TD}} \left( {{\text{C}}_{\text{i}} } \right)/\sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TB}} \left( {{\text{C}}_{\text{i}} } \right) $$
(2)

N: Total number of classes in the class inheritance tree. For rest of all equations, N represents the same.

Average Number of Direct Child (ANDC).

Metric is the ratio of the total number of immediate child to the total number of classes in the inheritance tree [10]. ANDC metric is calculated as follows:

$$ {\text{ANDC }} = \, \sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TDC}} \left( {{\text{C}}_{\text{i}} } \right)/N $$
(3)

Average Number of Indirect Child (ANIC).

Metric is the ratio of the total number of indirect child to the total number of classes in the inheritance tree [10]. ANIC metric is calculated as follows:

$$ {\text{ANIC }} = \, \sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TIC}} \left( {{\text{C}}_{\text{i}} } \right)/N $$
(4)

3 Proposed Inheritance Metrics

We have proposed four inheritance metrics which will give information about complexity of class inheritance hierarchy in terms of super classes/parent classes, ancestors and descendants. These are named as Average Number of Direct Parents (ANDP) metric, Average Number of Indirect Parents (ANIP) metric, Average Number of Ancestor Classes (ANAC) metric and Average Number of Descendant Classes (AND) metric. These metrics with formulas and assumptions are explained as follows.

Average Number of Direct Parents (ANDP) Metric is the ratio of the total number of direct or immediate parents to the total number of classes in the inheritance tree. Formula to calculate ANDP metric along with assumption is given as follows:

$$ {\text{ANDP }} = \, \sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TDP}} \left( {{\text{C}}_{\text{i}} } \right)/N $$
(5)
  • ANDP metric gives information about number of direct parents/direct super classes in class inheritance tree.

  • ANDP metric measures that from how many direct super classes; subclasses are going to inherit the properties such as methods and attributes.

Average Number of Indirect Parents (ANIP) Metric is the ratio of the total number of indirect parents to the total number of classes in the inheritance tree. Equation 6 has the formula to calculate ANIP metric and assumption are as follows:

$$ {\text{ANIP }} = \, \sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TIP}} \left( {{\text{C}}_{\text{i}} } \right)/N $$
(6)
  • ANIP metric gives us indication of how many indirect parents/indirect super classes are going to affect subclasses in class inheritance tree.

  • Deepness of a class in class inheritance tree shows higher degree of inheritance, thus it can be hard to comprehend a system with many inheritance layers.

  • Greater value of ANIP metric indicates that many methods might be reused.

Average Number of Ancestor Classes (ANAC) Metric is the ratio of the total number of ancestor classes to the total number of classes in the inheritance tree. ANAC metric is calculated with formula of Eq. 7. Later on are assumptions.

$$ {\text{ANAC }} = \, \sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TA}} \left( {{\text{C}}_{\text{i}} } \right)/N $$
(7)
  • ANAC metric gives information about how many ancestor classes are present in class inheritance tree.

  • Greater value of ANAC of class inheritance tree gives the indication that tree has deeper inheritance hierarchy than a class inheritance tree having low value of ANAC.

  • Class Inheritance tree having shallow inheritance hierarchy constitute lesser design complexity, since less methods and classes are involved.

Average Number of Descendants Classes (AND) Metric is the ratio of the total number of descendant classes to the total number of classes in the inheritance tree. Equation 8 is showing AND metric calculation formula.

$$ {\text{AND }} = \, \sum\limits_{{{\text{i}} = 0}}^{\text{N}} {\text{TD}} \left( {{\text{C}}_{\text{i}} } \right)/N $$
(8)

Assumptions of AND Metrics are as following:

  • AND metric gives information about how many descendant classes are present in class inheritance tree.

  • Low value of AND of class inheritance tree gives the indication that tree has shallow inheritance hierarchy than a class inheritance tree having high value of AND.

  • AND metrics provides information about inheritance and inheritance plays important role in reuse of already designed classes when designing a new class.

4 Examples for Illustration

In order to explain and illustrate these proposed inheritance metrics and to compare them with existing ones we have taken two class inheritance trees. In these class inheritance trees rectangular boxes represents classes and arrow symbol show relationship between these classes.

In first example (See Fig. 1) there is a simple class inheritance tree having 6 classes. Class A is root class and then downward there are descendants of root class A. As class B and Class C are child classes of Class A. Class D and Class E are child classes of Class C similarly Class F is child class of Class B. It is quite obvious from Fig. 1 that inheritance tree is simple in structure as it has little depth and breadth.

Fig. 1.
figure 1

Class inheritance tree having less depth and breadth

In second example (See Fig. 2) we have taken a little complex class inheritance tree having 12 classes. Class A is root class and then downward there are descendants of root class A. As Class B is child class of Class A. Classes C, D, E and F are child classes of Class B. Classes H and I are child classes of class C and Class H and I are parents of Class J. Similarly Classes D, E and F are parents of Class G and Class G is Parent Class for Classes K and L. Figure of this 2nd class inheritance tree shows that this inheritance tree is bit complex in structure as it has more depth and breadth as compared to class inheritance tree of 1st example.

Fig. 2.
figure 2

Class inheritance tree having more depth and breadth

5 Results of Existing and Proposed Metrics

In Tables 1 and 2, we have presented the calculation of existing and proposed inheritance metrics for class inheritance tree of example 1 and example 2 respectively. The entire results of existing and proposed inheritance metrics for both class inheritance trees are shown in Table 3 and also in Fig. 3 in graphical form.

Table 1. Existing and proposed metrics calculations for inheritance tree of Fig. 1
Table 2. Existing and proposed metrics calculations for inheritance tree of Fig. 2
Table 3. Result of existing and proposed inheritance metrics for both class inheritance trees of Figs. 1 and 2
Fig. 3.
figure 3

Graphical representation of result of existing and proposed inheritance metrics for both class inheritance trees of Figs. 1 and 2.

Results of existing and proposed inheritance metrics values for both class inheritance trees can be shown graphically as in Fig. 3 as both inheritance trees are represented here on x-axis and metric values on y-axis.

6 Analysis of Results

From above mentioned Table 3 and graph of Fig. 3, we have certain observations regarding existing and proposed inheritance metrics with respect to reusability.

  • DBRM metric value of inheritance tree of Fig. 2 is lower than that of inheritance tree of Fig. 1, means Fig. 2 has low ratio of derived classes to base classes.

  • AID Metric is concerned with depth of inheritance tree so lower AID metric value indicates low design complexity, which leads to easy maintainability and more understand-ability but low reusability.

  • Similarly from Figs. 1, 2 and 3 and Table 3, it can be analyzed that inheritance in Fig. 2 reuse more properties (ANDC and ANIC Metric value) means better reusability as inheritance of Fig. 2 has high value of ANDC and ANIC metrics.

  • Figure 2 has greater ANIP metric value as compared to inheritance tree of Fig. 1 means class inheritance in Fig. 2 is deeper. Deeper tree constitute greater design complexity, as more classes are involved. We can say that higher ANIP metric value leads to more reusability but lower maintainability and understandability.

  • Table 1 and Fig. 3 shows that ANDC and ANDP metrics values are similar. It indicates that any of these metric can be used to find out overall depth of inheritance of inheritance tree which will determine the reusability of that component.

  • From Table 3 it can be analyzed that value of ANIC metric (Existing) and ANIP metric (proposed) for each inheritance tree is similar. So it also gives us a facility to use both these metrics alternatively. Same is indicated by graph given above.

  • Both (proposed metrics) ANAC and AND Metric values indicate the depth of inheritance of class inheritance tree. It can be easily analyzed that class inheritance tree of Fig. 2 has more values of ANAC and AND Metric, which shows Fig. 2’s tree has deeper inheritance hierarchy and more design complexity and more reusability than class inheritance tree of Fig. 1.

7 Conclusion and Future Works

Class design plays vital role in OO system’s development and inheritance supports the class hierarchy design. Reusability is related to depth and shallowness of inheritance hierarchy so it is essential to determine the intricacy of inheritance hierarchy. We have proposed different class inheritance metrics to give information about inheritance complexity with respect to parent classes, ancestor and descendant classes.

Two of our proposed metrics ANDP and ANIP tend to provide an alternate solution to discover intricacy of class inheritance as compared with existing inheritance metrics ANDC and ANIC because our proposed ones provide same results in terms of super classes so we come to know that intricacy of inheritance hierarchy is same w.r.t parent classes as that of subclasses. We have proposed two more inheritance metrics as AND metric and ANAC metric which can be used interchangeably according to ease and given conditions. These inheritance metrics are involved in finding intricacy of class inheritance hierarchy that has dominant effects on software reusability.

In future, this work can be extended for deeper and complicated inheritance trees because class inheritance trees studied here are small as compared to inheritance trees used usually in systems so that effect of these proposed inheritance metrics on reusability process can be evaluated more precisely and effectively.