Why is Inheritance Important?

Similar documents
Stat 5303 (Oehlert): Unbalanced Factorial Examples 1

Student Performance Q&A:

Inheritance Usage Patterns in Open-Source Systems. Jamie Stevenson and Murray Wood. University of Strathclyde, Glasgow, UK

A study of the impact of C++ on software maintenance

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Enhanced Entity- Relationship Models (EER)

THE ADHERENCE OF OPEN SOURCE JAVA PROGRAMMERS TO STANDARD CODING PRACTICES

SPSS INSTRUCTION CHAPTER 9

Object-Oriented Design

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

MechEng SE3 Lecture 7 Domain Modelling

ava with Object-Oriented Generic Programming+ Java Java with Object-Oriented + Generic Programming by Paul S. Wang sofpower.com

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010

CS211 Lecture: Relationships Between Classes: Dependency, Inheritance, and Realization

Design Pattern and Software Architecture: IV. Design Pattern

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Maintenance Phase. Maintenance Type

CPS 506 Comparative Programming Languages. Programming Language

San José State University Department of Computer Science CS151, Object Oriented Design, Section 04, Fall, 2016 (42968)

CS558 Programming Languages Winter 2013 Lecture 8

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

Multiple Regression White paper

San José State University Department of Computer Science CS151, Section 04 Object Oriented Design Spring 2018

STATISTICS (STAT) Statistics (STAT) 1

Programming in Visual Basic with Microsoft Visual Studio 2010

Getting started with simulating data in R: some helpful functions and how to use them Ariel Muldoon August 28, 2018

Data Analysis and Solver Plugins for KSpread USER S MANUAL. Tomasz Maliszewski

1.2. Pictorial and Tabular Methods in Descriptive Statistics

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Making Tables and Figures

11. Abstract Classes and Interfaces

LAB 5 Implementing an ALU

MTAT Software Engineering. Written Exam 17 January Start: 9:15 End: 11:45

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

An Exploratory Analysis of Semantic Network Complexity for Data Modeling Performance

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

Java Programming Lecture 7

Verification and Validation. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 22 Slide 1

BCS THE CHARTERED INSTITUTE FOR IT. BCS Higher Education Qualifications BCS Level 6 Professional Graduate Diploma in IT EXAMINERS' REPORT

UNIT II Requirements Analysis and Specification & Software Design

Stacks, Queues & Trees. The Stack Interface. The Stack Interface. Harald Gall, Prof. Dr.

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

Introduction to UML What is UML? Motivations for UML Types of UML diagrams UML syntax Descriptions of the various diagram types Rational Rose (IBM.. M

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

Design First ITS Instructor Tool

CMPE/SE 135 Object-Oriented Analysis and Design

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

These are notes for the third lecture; if statements and loops.

Object Visibility: Making the Necessary Connections

A4 Explain how the Visitor design pattern works (4 marks)

Computer Science 225 Advanced Programming Siena College Spring Topic Notes: Inheritance

bold The requirements for this software are: Software must be able to build, debug, run, and col ect data from Discrete Event Simulation models

1. BlueJ bank example with subclasses of BankAccount 2. Transparency of UML diagram for BankAccount class hierarchy

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Inheritance & Polymorphism

Building custom components IAT351

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

CPSC 427: Object-Oriented Programming

The Design Patterns Matrix From Analysis to Implementation

Data can be in the form of numbers, words, measurements, observations or even just descriptions of things.

Concepts 6. OOAD Part II. BlueJ ex 5.1. OO and inheritance. Intro to inheritance. The DoME project is a database for multimedia entertainment.

CPSC 427: Object-Oriented Programming

Topics in Object-Oriented Design Patterns

1. General Information Course Title: CSCI-605 Advanced Object-Oriented Programming Concepts Instructor: Hans-Peter Bischof Office: Telephone:

Sunburst Design - SystemVerilog UVM Verification Training by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

( ) = Y ˆ. Calibration Definition A model is calibrated if its predictions are right on average: ave(response Predicted value) = Predicted value.

COURSE 2 DESIGN PATTERNS

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

CISC370: Inheritance

1: Introduction to Object (1)

Usability Report. Author: Stephen Varnado Version: 1.0 Date: November 24, 2014

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 11/03/2015

Software Service Engineering

An Example in Data Modeling in UML

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

Object Relationships

DISCRETE COMPUTER SIMULATION WITH JAVA

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism

3 Product Management Anti-Patterns by Thomas Schranz

Lecture 15 Software Testing

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Module 10 Inheritance, Virtual Functions, and Polymorphism

Object-Oriented Software Engineering Practical Software Development using UML and Java

The Legacy Bridge Problem. Douglas Lyon and Chris Huntley

Java Software Solutions for AP Computer Science 3rd Edition, Lewis et al. 2011

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Software Development

DESIGN PATTERN - INTERVIEW QUESTIONS

JEDIS: The JMP Experimental Design Iterative Solver 1

Systematic errors Random errors

Library Web Presence Award

Object-Oriented Concepts and Design Principles

Building Better Parametric Cost Models

Tuesday, October 4. Announcements

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Transcription:

Universität Karlsruhe (TH) Forschungsuniversität gegründet 1825 A Controlled Experiment on Inheritance Depth as a Cost Factor in Maintenance Walter F. Tichy University of Karlsruhe Why is Inheritance Important? Inheritance and polymorphism is an essential part of OO-modeling class hierarchies can structure a domain cleanly reuse by extension is convenient how would you do certain designs without inheritance, such as template method, compositum, strategy, factory method, extensible frameworks, and others? 2

Problems with Inheritance Everybody has been lost in class libraries. Sun s SWING and AWT library consists of over 800 classes; Java 1.4 contains over 2700 classes. OO design guidelines recommend using inheritance sparingly (choose classes first, structure class hierarchy later, prefer composition over inheritance, don t use subclassing unnecessarily, inherit only interfaces, not implementations). design pattern books use single-level inheritance only, inheriting mostly interfaces. 3 Inheritance Considered Harmful Difficulty of testing increases with inheritance depth (Basili et al, 1996). Sommerville, 1992:...class inheritance is not essential and may sometimes confuse a design, because an object class cannot be understood on its own without reference to any superclass. Wilde et al, 1993: Understanding of a single line may require tracing a chain of method invocations through several different object classes and up and down the object hierarchy to find where the work is really getting done. Soloway s delocalized plans: design decisions spread out over several locations in a program. 4

What do we make of this? Should we go back to programming with abstract data types without inheritance, only allow interface inheritance? But what about the potential benefits of inheritance: clarity of conceptual modeling design patterns (e.g. compositum, template method) sharing of code convenient extension frameworks Can you program GUIs reasonably without inheritance? Is there a serious problem lurking here? 5 Enter Experiments Experiment by Daly et al, 1996: Task: adding new class to existing program Two different programs: program A: 3 vs 0 levels program B: 5 vs 0 levels 0-level programs were flattenend versions of 3 and 5 level programs. Levels: an n-level program is one where the maximum number of edges traversed from root to leaves is n. 6

Results: Maintaining 5 levels is slower than 0 levels. Maintaining 0 levels is slower than 3 levels. Summary: 3 levels is best! But wait! 3 levels seems arbitrary. Can this be explained? We ve all programmed with way more than three levels (e.g., C++, Java, GUIs) and did not necessarily see difficulties because of inheritance. 7 Are there Replications? Cartwright, 1998: replicated 3 vs 0 levels with 5-person teams (undergraduates). Result: 0 levels is faster than 3! Harrison, 1999: identify changes (undergraduates): Result: 0 levels causes fewer mistakes than 3 and 5! Something is wrong here, but what? Experiment flawed? Subjects inexperienced? Program/task too simple? Flattening artificial? Random fluctuations? 8

The Karlsruhe Inheritance Depth Experiments Hypothesis 1: Given two functionally identical versions of a program that differ in inheritance depth, the version with deeper inheritance requires more time for maintenance. Hypothesis 2: Given two functionally identical versions of a program that differ in inheritance depth, the version with deeper inheritance causes lower quality during maintenance. 9 Major Changes in Design of Experiments Longer programs: Karlsruhe programs were 2 to 4 times longer than the prior programs (more realistic). More complicated and varied change tasks, more understanding of the program necessary (prior experiments only required the addition of a single class, similar to an existing one). Subjects were given source code plus class diagram (prior experiments provided only source code, no class diagram). Subjects decided on their own when finished (in prior experiments, instructor checked programs and asked subjects to continue when flaws were present. This is unrealistic in work environments.) 10

Experiment Details Experiment 1 (Group G): 57 Graduate Computer Science Students out of a class of 70, selected if they achieved 75% of available points in Java course. Had 8.1 years of programming experience on average. Performed Task 1 and then Task 2a/2b Experiment 2 (Group U): 58 Undergraduate Computer Science Students out of a class of 160. Had 6.1 years of programming experience. Performed Task 2a and then Task 2b 11 More Experiment Details Single program in 5-, 3-, and 0-level versions. Original program had 5 levels, 28 classes, 80 method bodies, 1200 lines. Equivalent 3 level program: 27 classes, 100 method bodies, 1340 lines (inherit only interfaces, never implementations, design pattern style ) Equivalent 0-level program: 20 classes, 160 method bodies, 2470 lines (expanded all inherited attributes, C-language style ) The 3- and 0-level programs were reasonable design alternatives. 12

Program: Börse Displays stock exchange data in various ways 13 Class Hierarchy of Börse (5 levels) 14

More Details Materials: source, OMT diagram. Subjects decide when to hand in. Independent variable: inheritance depth (0, 3, 5). Subject ability was balanced according to score on previous assignment or largest program they had written. Dependent variables: elapsed time (minutes), correctness (discrete grading scale) 15 Tasks Task 1: Y2K, i.e. convert program from 2-digit to 4-digit years. Solution involved finding all occurrences of a method. 5-level program had half the change locations as the others. Task 2a: add new type of display and extend menu. Inherit (3, 5-level) or copy (0-level) part of solution. adapt code from a chart class. Overwrite behavior from superclass (5-level hardest). Task 2b: add another type of display. solution can profit from 2a, but 5-level program is the simplest to handle (clone a class). 16

Procedures Subjects implemented their solutions using JDK 1.1 and tested them. Four parts: questionnaire and pretest for Java s inheritance rules assignment 1 assignment 2 postmortem questionnaire Measured time between handing out assignment and handing in solution. Also intercepted each compilation run and time stamped. Grading on a fixed classification of error types (points). 17 Results Inconclusive for hypothesis 1. Modest support for hypotheses 2. 0-level program requires more modifications than 5-level, but is almost as fast to do as 5-level program (difference p=0.2). 3- and 5-level program have about the same number of mods, but 3-level slower to modify (p=0.075). 0-level programs received most points. 18

Results Modest support for hypothesis 1. Inconclusive for hypothesis 2. to copy and modify than to trace up and down the inheritance hierarchy. 19 0-level significantly faster to do than the others. 3-level and 5-level about the same. Correctness about equal in all three. Most code to be added in level 0, but it is apparently easier Results Weak support for both hypotheses. 0-level and 3-level programs about the same, faster to modify than 5-level. Correctness decreases with greater inheritance depth. Time difference between 0-level and 5-level is significant (p=0.038). 20

Results 5-level program significantly faster to change than the others (p<0.01). 3-level and 0-level were about the same (p=0.26). No significant differences in correctness. However, task 2b is exceptionally simple for 5-level program. 21 Results Task 1(Y2K), Goup G 0-level program requires more mods than 5-level, but is almost as fast to do as 5-level program (difference p=0.2). 3- and 5-level program have about the same number of mods, but 3-level slower to modify (p=0.075). 0-level programs received most points. Inconclusive for hypothesis 1. Modest support for hypotheses 2. 22

Results Task 2a+2b, Group G 0-level significantly faster to do than the others. 3-level and 5-level about the same. Correctness about equal in all three. Most code to be added in level 0, but it is apparently easier to copy and modify than to trace up and down the inheritance hierarchy. Modest support for hypothesis 1. Inconclusive for hypothesis 2. 23 Results Task 2a, Group U 0-level and 3-level programs about the same, faster to modify than 5-level. Correctness decreases with greater inheritance depth. Time difference between 0-level and 5-level is significant (p=0.038). Weak support for both hypotheses. 24

Task 2b, Group U 5-level program significantly faster to change than the others (p=0.006, 0.004). 3-level and 0-level were about the same (p=0.26). No significant differences in correctness. However, task 2b is exceptionally simple for 5-level program: clone an entire existing class, no actual method changes. 25 Result Summary Modest Support for the hypothesis that 0-level is faster and better to maintain than 3-level or 5-level programs. Stark contrast to experiment by Daly. In line with experiments by Cartwright. If correct, should we flatten all OO-programs? Which of these experiments is right? More useful question: Is there a better explanation than using inheritance depth? 26

What other Variables affect Maintenance Time? Figure out what needs to be done for a default solution strategy for each task. Test a number of potential predictors, such as classes, method bodies, lines, investigated methods, hierarchy changes, solution methods; build linear regression model. Best predictor in linear regression model: the number of methods investigated in default solution strategy for each task. Explains 84% of variation This is true when using ALL data (Daly s, Cartwright s, and our own) for the add class tasks: 16 groups. 27 Several Models T= 6.9m + 28 [min], R 2 =0.84 m is number of methods to be understood T= 4.5h + 61 [min], R 2 =0.55 h is number of hierarchy changes T = 7.8d + 70 [min], R 2 =0.10 d is the inheritance depth R 2 is the variance in average group work time explained by the model. R 2 =1 means perfect linear correlation; R 2 =0 means there is none. Clearly, inheritance depth is a poor predictor! 28

T = 6.9m + 28 Dashed lines show 90% confidence band. Size of circle/square represents inheritance depth. 29 Two Better Models T = 8.9m exp=l + 5.9m exp=h + 24, R 2 =0.94 takes experience into account (Low, High) T = 9.3m exp=l + 6.3m exp=h - 3.3d + 27, R 2 =0.96 takes experience and inheritance depth into account Only after methods examined and experience level are factored into the model, does inheritance depth per se make a small contribution. 30

T = 8.9m exp=l + 5.9m exp=h + 24 Dashed lines show 90% confidence band. Size of circle/square represents inheritance depth. 31 Conclusions: There is no Simple Answer In experiments, increased inheritance depth slightly increased maintenance time and errors. Positive effects of inheritance (less code duplication, less consistency checking) is perhaps visible in larger programs with complex modifications. Methods to be examined is a much better predictor for maintenance effort than inheritance depth. Inheritance depth is not in itself an important factor for maintenance effort. The real cost drivers may be number of methods analyzed, prior knowledge of the program, the degree of delocalization of information, or other aspects. 32

Threats to Validity Internal Validity: The conversion to level-3 and level-0 programs may have introduced differences unrelated to inheritance depth (unlikely, since straightforward conversion). External Validity/Generalizability: Students have less experience than professionals. Professionals may do better. However, not length of experience, but experience with application is important. The maintenance tasks may not be typical. The programs may not be typical (real programs are larger, may have different structural complexity, may have poorer documentation.) 33