New Inheritance Models That Facilitate Source Code Reuse in Object-Oriented Programming
Total Page:16
File Type:pdf, Size:1020Kb
NEW INHERITANCE MODELS THAT FACILITATE SOURCE CODE REUSE IN OBJECT- ORIENTED PROGRAMMING By HISHAM M. AL-HADDAD Bachelor of Science Yarmouk University lrbid, Jordan 1986 Master of Science Northrop University Los Angeles, California 1988 Submitted to the Faculty of the Graduate College of the Oklahoma State University in partial fulfillment of the requirements for the degree of DOCTOR OF PHILOSOPHY July, 1992 Oklahoma Statt.' Ur1iv. Library NEW INHERITANCE MODELS THAT FACILITATE SOURCE CODE REUSE IN OBJECT- ORIENTED PROGRAMMING C/ wU::r-~ B I A~c;p .... _.-~ Dean of the Graduate CoUege ii PREFACE Code reusability is a primary objective in the development of software systems. The object-oriented programming methodology is one of the areas that facilitate the development of software systems by allowing and promoting code reuse and modular designs. Object-oriented programming languages (OOPLs) provide different facilities to attain efficient reuse and reliable extension of existing software components. Inheritance is an important language feature that is conducive to reusability and extensibility. Various OOPLs provide different inheritance models based on different interpretations of the inheritance notion. Therefore, OOPLs have different characteristics derived from their respective inheritance models. This dissertation is concerned with solutions for three major problems that limit the utilization of inheritance for code reusability. The range of object-oriented applications and thus the usage of object-oriented programming in general is also discussed. The three major problems are: 1) the relationship between inheritance and other related issues such as encapsulation, access techniques, visibility of inheritance, and subtyping; 2) the hierarchical structure imposed by inheritance among classes; and 3) the accessibility of previous versions of the modified methods defmed in classes located at higher levels of the inheritance structure than the parent classes. 1be proposed solutions for these problems are presented as new inheritance models that facilitate code reuse and relax the restrictions imposed on inheritance models by languages. A survey and taxonomy of the conventional inheritance models, and a comparison and analysis of some of the common OOPLs are also presented in the dissertation. iii ACKNOWLEDGMENT First, I would like to express my sincere appreciation to my dissertation advisor, Dr. K.M. George, for his continuous and consistent guidance, dedication, kindness, and valuable instruction throughout my graduate work. His encouragement and motivation has been the driving force in the completion of this work. Special thanks are due to my advisory committee member, Dr. Mansur Samadzadeh, for his consistent support, valuable suggestions, and critical review of my research work. I would like also to thank other members of my advisory committee, Dr. G.E. Hedrick, J.P. Chandler, and W.B. Powell, for serving on my graduate committee and for their advice and support. I would like to extend my thanks to all of my friends, colleagues, and staff members, specially Anna Ventris and Janice Bryan, for their help and assistance. I would like to take this opportunity to thank my family. My deepest love and thanks go to my parents for their prays and spirit of encouragement throughout my academic studies. I also take this opportunity to extend my appreciation and thanks to my brothers and sisters for their moral support. Special appreciation and thanks to my brothers, Ali and Khalid, for their moral and financial support during my undergraduate and graduate studies. Finally, my love and thanks to my wife, MingChing, for her patience and moral support that gave me the motivation and inspiration to complete my graduate studies. Thank you all. iv TABLE OF CONTENTS Chapter Page I. INTRODUCTION 1 1.1 Prologue . 1 1.2 aasses . 2 1.3 Objects . 3 1.4 Inheritance . 4 1.5 Overview of the Dissertation . 9 II. LITERATURE REVIEW . 10 2.1 Introduction . 10 2.2 Oasses . 11 2.2.1 Instance Variables and Methods . 16 2.3 Instantiation . 19 2.4 Inheritance . 21 2.4.1 Subtyping . 31 2.4.2 Problems with Current Inheritance Models . 33 2.5 Message Passing . · . 36 2.6 Encapsulation . 38 2.7 Polymorphism and Binding . 40 2.8 Definitions . 42 ill. INHERITANCE IN OBJECf-ORIENTED PROGRAMMING LANGUAGES: A TAXONOMY AND SURVEY . 45 3.1 Introduction . 45 3.2 A Survey of Inheritance Mechanisms and Access Techniques . 46 3.2.1 Trellis/()wl . 47 3.2.2 c++ . 50 3.2.3 Eiffel . 54 3.2.4 CommonObjects . 57 3.2.5 ~s . ~ . 60 3.2.6 Flavors . 63 3.2.7 Smalltalk:-80 . 66 3.2.8 Simula . 70 v Chapter Page 3.3 Subtyping and Inheritance . 74 3.4 A Binary-Tree Taxonomy Model . 75 3. .5 Discussion . 81 3.6 Summary . 83 IV. APPROACHES TO REUSABILITY IN C++ AND EIFFEL . 88 4.1 Introduction ·. 88 4.2 Design Objectives and Highlights of the Two Languages . 90 4.2.1 Eiffel . 90 4.2.2 C++ . 94 4.3 Inheritance and Reusability . 95 4.3.1 Eiffel . • . 96 4.3.2 C++ . 99 4.4 Discussion . 105 4.5 Summary . 108 V. AN OBJECT-BASED INHERITANCE MODEL . 110 5.1 Introduction . 110 5.2 The Proposed Object-Based Inheritance Model (TIM) . 111 5.2.1 Semantics and Composition of an Object . 113 .5.2.2 Internal Structure of an Object . 115 5.2.3 Object Interfaces . • . • 117 5.2.4 Message Passing Techniques . 117 5.2.5 Multiple Inheritance . 118 5.2.6 Object Creation and Deletion . 119 5.2.7 Inheritance Hierarchy . 122 5.3 Examples Represented in the Proposed Model . 124 S.4 Discussion . 127 5.5 Summary . 129 VI. A FEEDBACK INHERITANCE MODEL . 130 6.1 Introduction . 130 6.2 Definitions . 131 6.3 Two Examples and Their Hierarchical Representations . 133 6.4 The Proposed Feedback Inheritance Model . 138 6.4.1 Definitions . 138 6.4.2 Feedback Inheritance • . 140 6.4.3 Semantics of Feedback Inheritance . • . 143 . 6.4.4 Message Passing ..................... ·. 145 6.5 Examples Represented in the Proposed Model . 148 Vl Chapter . · Page 6.6 Discussion . 152 6.7 Summary . 154 VII. AN IMPLEMENTATION INHERITANCE MODEL . 156 7.1 lnttod.uction . IS6 7.2 Background . 157 7.2.1 Eiffel . 157 7.2.2 C++ . 158 7.2.2.1 Overloading of Functions . 158 7.2.2.2 Virtual Functions . 160 7.2.2.3 Abstract Classes . 162 7.2.3 CI..OS . 162 7.2.4 Smalltalk-80 . 164 7.3 Classes and Slots . 166 7.4 Behavior Slots . 168 7 .4.1 Syntax of Behavior Slots . 170 7.5 Aggregates and Behavior Slots . 171 7.6 General Messages . 174 7.6.1 Procedure Calls . 175 7.7 The Proposed Implementation Inheritance Model . 176 7.8 Conceptual View of Implementation Inheritance . 177 7.9 An Implementation Scheme for Implementation Inheritance . 181 7.9.1 Organization of the 1-Index . 183 7.9.2 Size of the I-Index . 184 7.9.3 Construction of the I-Index . 186 7.9.3.1 Single Inheritance . 186 7.9.3.2 Multiple Inheritance . ..