A Comparative Study on the Effect of Multiple Inheritance Mechanism in Java, C++, and Python on Complexity and Reusability of Code

A Comparative Study on the Effect of Multiple Inheritance Mechanism in Java, C++, and Python on Complexity and Reusability of Code

(IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 8, No. 6, 2017 A Comparative Study on the Effect of Multiple Inheritance Mechanism in Java, C++, and Python on Complexity and Reusability of Code Fawzi Albalooshi Amjad Mahmood Department of Computer Science Department of Computer Science University of Bahrain University of Bahrain Kingdom of Bahrain Kingdom of Bahrain Abstract—Two of the fundamental uses of generalization in Booch, there are two problems associated with multiple object-oriented software development are the reusability of code inheritance and they are how to deal with name collisions from and better structuring of the description of objects. Multiple super classes, and how to handle repeated inheritance. He inheritance is one of the important features of object-oriented presents solutions to these two problems. Other researchers [4] methodologies which enables developers to combine concepts and suggest that there is a real need for multiple inheritance for increase the reusability of the resulting software. However, efficient object implementation. They justify their claim multiple inheritance is implemented differently in commonly referring to the lack of multiple subtyping in the ADA 95 used programming languages. In this paper, we use Chidamber revision which was considered as a deficiency that was and Kemerer (CK) metrics to study the complexity and rectified in the newer version [5]. It is clear that multiple reusability of multiple inheritance as implemented in Python, inheritance is a fundamental concept in object-orientation. The Java, and C++. The analysis of results suggests that out of the three languages investigated Python and C++ offer better ability to incorporate multiple inheritance in system design and reusability of software when using multiple inheritance, whereas implementation will better structure the description of objects Java has major deficiencies when implementing multiple modeling, their natural status and enabling further code reuse inheritance resulting in poor structure of objects. as compared to single inheritance. Java, C++, and Python are three widely used OO Keywords—Reusability; complexity; Python; Java; C++; CK programming languages in academia and industry. Java has metrics; multiple inheritance; software metrics secured its position as the most widely used OO programming I. INTRODUCTION language due to many reasons including its network-centric independent platform and powerful collection of libraries Inheritance is one of the fundamental concepts of object- known as Java APIs (Application Programming Interface). oriented (OO) software development. There are two types: Nevertheless, Java has a limitation when it comes to single and multiple. Single inheritance is the ability of a class implementing multiple inheritance. C++ is another widely used to inherit the features of a single super class with more than a programming language and is considered to be the most single inheritance level i.e. the super class could also be a comprehensive due to its support to a variety of programming subclass inheriting from a third class and so on. Multiple styles such as procedural, modular, data abstraction, object- inheritance, on the other hand, is the ability of a class to inherit oriented and generic programming [1], [2]. It supports single from more than a single class. For example, a graphical image and multiple inheritance in which a child class can inherit the could inherit the properties of a geometrical shape and a properties of a single parent class and multiple parents. Python picture. Stroustrup [1], [2] states that multiple inheritance is a powerful object-oriented general-purpose programming allows a user to combine independent concepts represented as language created by Guido van Rossum [6]. It has wide range classes into a composite concept represented as a derived class. of applications from Web development to scientific and For example, a user might specify a new kind of window by mathematical computing to desktop graphical user Interfaces. selecting a style of window interaction from a set of available It is a simple language; open source, portable across platforms, interaction classes and a style of appearance from a set of extensible and embeddable, interpreted, and has large standard display defining classes. libraries to solve common tasks. Similar to C++ single and There is wide debate on the usefulness of multiple multiple inheritance is supported by Python. An empirical inheritance and whether the complexities associated with it study on the use of inheritance in Python systems was carried justify its implementation. Though some researchers such as out by Orru et al. [7]. More details about the implementation of Stroustrup [1], [2] are convinced that it can easily be multiple inheritance in these languages are discussed in implemented. He states that multiple inheritance avoids Section 2. replication of information that would be experienced with To the best of our knowledge there has been no studies single inheritance when attempting to represent combined comparing the complexity and reusability of commonly used concepts from more than one class. Booch [3] asserts that it is object-oriented programming languages. In this paper, we good to have inheritance when you need it. According to present implementation of multiple inheritance and use CK 109 | P a g e www.ijacsa.thesai.org (IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 8, No. 6, 2017 (Chidamber and Kemerer) [8] metrics to study the complexity } and reusability of multiple inheritance as implemented in Python, Java, and C++. For this purpose, we used a sample class B implements IB{ design and code from real-life systems involving multi-level // Implementation class for the interface IB multiple inheritance and its implementation. public string b(IB self) {return self.b1(); } The rest of the paper is organized as: Section 2 presents the implementation of multiple inheritance in Java, C++, and protected string b1() {return “B”;} Python. Section 3 details the complexity and reusability } analysis for the three languages. It discusses software metrics and how they are applied in the measurement of the complexity and reusability followed by a discussion of the results. In class C extends A implements IB { Section 4 we address the current use of multiple inheritance in open source software and the impact of such practice on its // Subclass inheriting from A and implementing IB’s complexity and reusability and Section 5 concludes the paper. interface II. MULTIPLE INHERITANCE IMPLEMENTATION IN JAVA, B b; // Innerclass as composition relationship C++, AND PYTHON public string b(IB self) {return b.b(this); } In Java, a class can singly inherit the properties of another protected string b1() {return “C”;} class. Java does not support multiple inheritance of classes, but it supports multiple inheritance of interfaces [9]. A strong protected string a1() {return “C”;} reason that prevents Java from extending more than one class } is to avoid issues related to multiple inheritance of attributes from more than one level which is referred to as the „diamond Program 1(a): Approximating multiple inheritance in Java. problem‟ [10]. This is a situation that occurs when implementing multiple inheritance in which a class inheriting class A { // The primary class to be inherited from two or more super classes with a common ancestor. The public string a() { return a1();} super classes inherit the common ancestor method(s) and/or attribute(s). This results to their child class to inherit multiple protected string a1() {return “A”;} versions of the same method(s) and/or attribute(s) (one from } each super class). Thus, a conflict arises during program execution involving the child class on which version of the same inherited method/attribute to use. Java interfaces do not have a state, thus do not pose such a threat. The more recent class B { // Implementation class for the interface IB Java 8 compiler resolves the issue of which default method a public string b() {return self.b1(); } particular class uses, however this solution has its limitations. To overcome Java‟s shortcoming in implementing multiple protected string b1() {return “B”;} inheritance, researchers investigated compromised solutions. } Two of the most commonly used approaches are termed as approximation [11] and delegation [12] of multiple inheritance. C++ overcomes the diamond problem with the use of virtual class C extends A, B { inheritance. Program 1(b) shows the implementation of multiple inheritance in C++ for the Java example shown in protected string b1() {return “C”;} Program 1(a). In Python the diamond problem is nicely protected string a1() {return “C”;} resolved using the “Method Resolution Order” approach which is based on the “C3 superclass linearization” algorithm. } Program 1(c) shows the implementation of multiple inheritance Program 1(b): Multiple inheritance in C++. in Python. class A { // The primary class to be inherited class A: public string a() { return a1();} def a(self): (return a1();) protected string a1() {return “A”;} def a1(): (return “A”) } interface IB { class B(A): // Second class to be inherited declared as an interface def b(self): (return b1();) public string b(IB self); def b1(): (return “B”) public string b1(); 110 | P a g e www.ijacsa.thesai.org (IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 8, No. 6, 2017 class C(A,B):

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us