
Traits Composing Classes from Behavioral Building Blocks Inauguraldissertation der Philosophisch-naturwissenschaftlichen Fakultat¨ der Universitat¨ Bern vorgelegt von Nathanael Scharli¨ von Zell (LU) Leiter der Arbeit: Prof. Dr. Stephane´ Ducasse Prof. Dr. Oscar Nierstrasz Institut fur¨ Informatik und angewandte Mathematik Traits Composing Classes from Behavioral Building Blocks Inauguraldissertation der Philosophisch-naturwissenschaftlichen Fakultat¨ der Universitat¨ Bern vorgelegt von Nathanael Scharli¨ von Zell (LU) Leiter der Arbeit: Prof. Dr. Stephane´ Ducasse Prof. Dr. Oscar Nierstrasz Institut fur¨ Informatik und angewandte Mathematik Von der Philosophisch-naturwissenschaftlichen Fakultat¨ angenommen. Bern, 03.02.2005 Der Dekan: Prof. P. Messerli Abstract Inheritance is well-known and accepted as a fundamental mechanism for reuse in object-oriented languages. Unfortunately, the main variants — single inheritance, multiple inheritance, and mixin inheritance — all suffer from conceptual and practical problems related to software reuse and robustness with respect to changes. In a first part of this thesis, we identify and illustrate these problems. To overcome these problems, we then present traits, a simple compositional model that extends single inheritance. A trait is essentially a (parameterized) set of methods; it serves as a behavioral building block for classes and is the primitive unit of code reuse. We develop a formal model of traits that establishes how traits can be composed to form other traits or classes, and we describe how we implemented traits in Squeak Smalltalk by bootstrapping a new language kernel. We present our experimental validation in which we apply traits to refactor parts of the Smalltalk kernel and library, and we develop a programming methodology around the usage of traits and the trait browser, the tool that we implemented to take full advantage of the availability of traits in the Squeak programming environment. i Acknowledgments First and foremost, I would like to express my gratitude to my advisors Oscar Nierstrasz and Stephane´ Ducasse. Oscar gave me the opportunity to work in his research group and provided me with tremendous professional support and excellent advice throughout my studies. Steph’s´ passion and energy are truly contagious. Our countless discussions were invaluable in developing the concepts in this thesis. I also would like to thank Steph´ for introducing me to all of the great technology and people and for educating me in the “French way of life”. Oscar and Steph,´ it was a great pleasure to work with you during all these years. I would also like to thank the other members of my Ph.D. committee, Andrew Black and Alan Kay. Andrew invited me to work with his research group at OGI in Portland. Despite the geographic distance, he provided me with continuous support during my Ph.D. I thank him for the valuable discussions, enjoyable pair programming sessions, and for helping make my papers fit to read. Alan also gave me the opportunity to work with him and his group in California. I especially appreciate that he was willing to share his fantastic knowledge and experience with me as well as many interesting stories from the past. Andrew and Alan, thank you for accepting to be part of my Ph.D. committee; I feel very lucky and honored. Very special thanks go to my family. I thank my parents, Rosmarie and Toni, and my siblings, Andrea, Matthias, and Petra, for their unending love and support and for the wonderful environment I grew up in. I have had a truly magical time with you and I cannot express how happy it makes me to be part of our family. Most importantly, I thank Rebecca — my love, my best friend and now also my wife — for being here and sharing her life, her love, and her future with me. There is nothing that could make me happier. Thanks also to Rebecca’s family for welcoming me into their lives. I would also like to thank my friends for all the adventures and the good times we have experienced together and for the support and advice you have given me. You know who you are, so I will not list you here. Just let me say that good friends are invaluable and that I feel extremely fortunate to know and be friends with every single one of you. You are the best. Many thanks also to all the colleagues who have helped me and collaborated with me during my work on traits. I especially thank Gilad Bracha for inspiring me with his dissertation and for kindly sharing with me his knowledge about mixins and other aspects of programming language design. Thanks also to Andreas Raab, who got me thinking about traits in the first place, Adrian Lienhard, who did a lot of work for the stable implementation of traits in Squeak, Philip Quitslund, who developed traits for mini-Java and shared his office with me during my visits to Portland, Stevan Little, who implemented traits in Perl, Matthias Zenger and Martin Odersky, who discussed their implementation of traits in Scala with us, and Jean-Guy Schneider, who reviewed some of our papers on traits. Next I would like to thank all the former and current members of the Software Composition Group. It was a pleasure to work with you: Franz Achermann, Gabriela Arevalo, Alexandre Bergel, Frank Buchli, Thomas Buhler,¨ Calogero Butera, Juan Carlos Cruz, Marcus Denker, Markus Galli,¨ Tudor Girba, Orla Greevy, Marc- Philippe Horvath, Andreas Hosbach, Markus Kobel, Stefan Kneubuhl,¨ Adrian Kuhn, Michael Locher, Liang Peng, Laura Ponisio, Lukas Renggli, Tamar Richner, Matthias Rieger, Andreas Schlapbach, Therese Schmid, Mauricio Seeberger, Daniele Talerico, Sander Tichelaar, David Vogel, and Roel Wuyts. I would also like to thank all the people that supported and hosted me during my travels and stays abroad. In particular, I thank the Squeak Group at Disney (now at Viewpoints Research and HP Labs) for making my ii iii internships and visits possible. The time I got to spend with you in California was truly unforgettable. Thanks also to the team at OGI in Portland for making my visits so smooth and pleasant. Finally, I would like to send my best to all the great people I have met and talked to at conferences, meetings, workshops, online and elsewhere. Nathanael Scharli¨ February 2005 iii Contents Abstract i 1 Introduction 1 1.1 Understanding the Problem . 1 1.2 Our Proposal: Traits . 2 1.3 Contributions . 3 1.4 Thesis Outline . 3 2 Problems with Inheritance 5 2.1 Composition and Decomposition Problems . 5 2.1.1 Decomposition Problems . 5 2.1.2 Composition problems . 7 2.2 Occurrences of these Problems in Real Languages . 9 2.2.1 Strongtalk and Jam . 9 2.2.2 C++ . 11 2.2.3 CLOS . 15 3 Traits 16 3.1 Traits – Composable Units of Behavior . 16 3.1.1 Classes and Methods . 17 3.1.2 Traits . 19 3.1.3 Composing Classes from Traits . 20 3.1.4 Composite Traits . 22 3.1.5 Conflict Resolution . 23 3.1.6 Well-definedness . 27 3.1.7 Refactoring, reachability and equivalence . 28 3.2 Evaluation . 31 3.2.1 Decomposition Problems . 31 3.2.2 Composition Problems . 31 3.3 Discussion . 32 3.3.1 Design Decisions . 33 3.3.2 C++ Revisited . 35 4 Implementation 39 4.1 Overview of the Smalltalk-80 Kernel Architecture . 39 4.1.1 Organization of Classes and Metaclasses . 39 4.1.2 The Kernel Classes . 40 4.2 Traits Design Rationale . 42 4.3 The New Language Kernel . 42 v vi CONTENTS 4.3.1 The New Kernel Classes . 42 4.3.2 Decomposition into Traits . 46 4.4 Flattening Traits at Composition Time . 46 4.5 Conclusions . 47 5 Tools and Methodology 48 5.1 Traits and Tools: Analysis . 48 5.2 The Trait Browser . 49 5.2.1 Overview . 49 5.2.2 Virtual Categories . 50 5.2.3 Using the Browser With Traits . 52 5.2.4 Implementation . 54 5.3 Programming Methodology . 59 5.3.1 The Roles of Classes and Traits . 60 5.3.2 Uniform Protocols . 60 5.3.3 Uncovering Hidden Structure . 64 5.3.4 Traits and Agile Methodologies . 65 5.4 Interaction between Language, Tools and Methodology . 66 6 Case Study: Refactoring the Smalltalk Collection Classes 67 6.1 The Smalltalk Collection Classes . 67 6.1.1 The Varieties of Collection . 69 6.1.2 Streams . 71 6.2 Analysis of the Collection Classes . 71 6.2.1 Unnecessary Inheritance . 72 6.2.2 Code Duplication and Inappropriate Hierarchies . 73 6.2.3 Conceptual Shortcomings . 74 6.3 Refactoring Results . 75 6.3.1 The New Collection Hierarchy . 75 6.3.2 The New Stream Hierarchy . 79 6.3.3 Measurements of the Refactored Classes . 79 6.3.4 Assessment of the Refactored Classes . 84 6.3.5 Design Decisions . 85 6.4 Discussion . 85 6.4.1 Lessons Learned . 85 6.4.2 Comparison to Other Approaches . 86 6.5 Conclusions . 88 7 Case Study: Trait-based Composition of Class Properties 90 7.1 Motivation and Overview . 90 7.2 Representing Class Properties As Traits . ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages143 Page
-
File Size-