Multiple & Repeated Inheritance

Similar documents
Multiple & Repeated! Inheritance!

Example Test Questions for Inheritance

Einführung in die Programmierung Introduction to Programming

Multiple Inheritance לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Object-Oriented Software Construction

Introduction to Programming. Lecture 20: More about inheritance. Multiple inheritance. Composite figures. Bertrand Meyer

Introduction to Eiffel

BON Business Object Notation Based on slides by Prof. Paige

Multiple Inheritance עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Inheritance and Substitution (Budd chapter 8, 10)

Eiffel: Analysis, Design and Programming

- 9/10 - Inheritance

Major Differences between Java and C++ Programming in C++ Multiple Inheritance

Lecture 13: Introduction to inheritance and genericity

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Classes The Static Structure

ETHZ D-INFK Final Exam Booklet

Design by Contract in Eiffel

Singleton Pattern Creational. » Ensure a class has only one instance» Provide a global point of access

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005

10 Feature adaptation

CAT calls (Changed Availability or Type)

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

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

Chapter 8: Class and Method Design

Lecture 14: More Inheritance & Genericity

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

Eiffel: An Advanced Introduction. Alan A. Snyder Brian N. Vetter

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

Classes! The Static Structure!

Inheritance. Transitivity

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

CS4215 Programming Language Implementation

Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Chapter 5 Object-Oriented Programming

Motivating Problem (2) Design for tree structures with whole-part hierarchies. The Composite Design Pattern

QUIZ. How could we disable the automatic creation of copyconstructors

Inheritance and Polymorphism

The architecture of Eiffel software 3.1 OVERVIEW classes clusters systems

Overloading, abstract classes, and inheritance

Instantiation of Template class

Programming in C# Inheritance and Polymorphism

Singleton Pattern Creational

Universe Type System for Eiffel. Annetta Schaad

G Programming Languages - Fall 2012

Siloed Reference Analysis

CGS 2405 Advanced Programming with C++ Course Justification

Multiple Inheritance, Abstract Classes, Interfaces

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

QUIZ. How could we disable the automatic creation of copyconstructors

Exheritance Class Generalisation Revived

Programming Languages. Benjamin J. Keller Department of Computer Science, Virginia Tech

UC Santa Barbara. CS189A - Capstone. Christopher Kruegel Department of Computer Science UC Santa Barbara

Largest Online Community of VU Students

Inheritance -- Introduction

COSC 3311 Software Design Report 2: XML Translation On the Design of the System Gunnar Gotshalks

Software Development. Modular Design and Algorithm Analysis

The Eiffel language. Slides partly based on :

TOWARDS FULLY-FLEDGED REVERSE INHERITANCE IN EIFFEL

Programming Languages and Compilers Qualifying Examination. Answer 4 of 6 questions.1

Chapter 3 Function Overloading

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

Lecture 18 CSE11 Fall 2013 Inheritance

Chapter 14. Inheritance. Slide 1

Inheritance and Interfaces

BON Business Object Notation Based on slides by Prof. Paige

Java Object Oriented Design. CSC207 Fall 2014

CS301 - Data Structures Glossary By

Subtyping (Dynamic Polymorphism)

JOURNAL OF OBJECT TECHNOLOGY

Francesco Nidito. Programmazione Avanzata AA 2007/08

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D)

Modules and Mixins. module Trig PI = def Trig.sin(x) #.. end CSC 517

Francesco Nidito. Programmazione Avanzata AA 2007/08

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

What are the characteristics of Object Oriented programming language?

Edition-Based Redefinition

Einführung in die Programmierung Introduction to Programming

OOP. Unit:3.3 Inheritance

Chapter 8: Data Abstractions

G Programming Languages Spring 2010 Lecture 8. Robert Grimm, New York University

Written by John Bell for CS 342, Spring 2018

The COURSE Class. class COURSE. create -- Declare commands that can be used as constructors make. feature -- Attributes title: STRING fee: REAL

CS 406: Syntax Directed Translation

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance)

Lecture 15: Object-Oriented Programming

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

Design Pattern: Composite

Encapsulation and Aggregation

Chapter 4. Action Routines

C#: advanced object-oriented features

Inheritance, Polymorphism and the Object Memory Model

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

Common Lisp Object System Specification. 1. Programmer Interface Concepts

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Ministry of Higher Education Colleges of Applied Sciences Final Exam Academic Year 2009/2010. Student s Name

C#: advanced object-oriented features

Transcription:

Multiple & Repeated Inheritance 21-1

Multiple Inheritance Example Combining two abstractions into one» COMPARABLE and NUMERIC are both useful abstractions > Some abstractions make use of both while others do not COMPARABLE NUMERIC STRING INTEGER COMPLEX 21-2

Repeated Inheritance Example Ancestor used in multiple paths to descendant UNIVERSITY_ PERSON TEACHER STUDENT TEACHING_ ASSISTANT 21-3

Inheritance Types Implementation abstraction that combines two implementations» ARRAY_STACK is both a STACK and and ARRAY Structural abstraction that combines two structures» HISTORY and STORABLE 21-4

Eiffel Global Inheritance Structure GENERAL GENERAL has all Eiffel global features & invariants ANY Customize ANY to have localized global features & invariants NONE 21-5

Feature Renaming Multiple & repeated inheritance lead to name clashes» What if two parents use the same name for a feature? > A common occurrence since good names are reused» How can the child refer to the appropriate feature? Answer» Rename one of the features give it an alias > Do not rely on overloading, not enough variation Overloading - distinguishes features by argument type and count 21-6

Example Renaming Suppose LONDON and LOS_ANGELES both have the feature foo Then we can define TORONTO as follows class TORONTO inherit LONDON rename foo as fog redefine fog end LOS_ANGELES rename foo as smog redefine smog end feature... end 21-7

Renaming Effects ldon : LONDON ; la : LOS_ANGELES ; tor : TORONTO Valid even after polymorphic assignment ldon.foo ; tor.fog la.foo ; tor.smog Invalid ldon.fog ; ldon.smog la.fog ; la.smog tor.foo 21-8

Redeclaration & Renaming Redeclaration» Keeps the name, changes the semantics Renaming» Keeps the semantics changes the name Can both rename and redefine» Rename first» Use new name when redefining Renaming can be useful to change the name to a more common one for the abstraction» TO push & pop (STACK) FROM add and remove (CONTAINER) 21-9

Repeated Inheritance Indirect» class B inherit A class C inherit A class D inherit B C B A C D Direct» class B inherit A A A B 21-10

Problems DRIVER age address violation_count pass_birthday pay_fee FRENCH_ DRIVER CANADIAN_ DRIVER FRENCH_CANANDIAN_DRIVER 21-11

Problems 2 DRIVER age address violation_count FRENCH_ DRIVER pass_birthday pay_fee CANADIAN_ DRIVER What about age? It is the same for both drivers! DO NOT rename! Only rename if inheriting different but identically named features FRENCH_CANANDIAN_DRIVER Have a single shared feature Sharing is not always appropriate violation_count, address, pay_fee are all different need to replicate for each driver 21-12

Repeated Inheritance Rule In a repeated inheritance» Versions of a repeatedly inherited feature inherited under the same name represent a single feature» Versions inherited under different names represent separate features, each replicated from the original in the common ancestor > Use rename to get replication rename pay_fee as pay_french_fee The rule applies to attributes as well as routines 21-13

Single Name Rule Definition» The final name of a feature in a class is > For an immediate feature, the name under which it is declared > For an inherited feature that is not renamed, its final name is (recursively) in the parent from which it is inherited > For a renamed feature, the name resulting from the renaming Single Name Rule» Two different effective features of a class may not have the same final name 21-14

Must Rename Consider the following attributes, even if the types agree must rename problem in D» Rename either version from B or C or both B problem C problem D 21-15

Conflicting Redefinition f A f ++ B C D In D have two different definitions of f» From B and from A through C Consider under» sharing» replication 21-16

Conflict Resolution Sharing f ++ B f A D C Inherit under same name» one version is deferred other is effective > No problem single name rule» both versions effective but redefined in D > No problem produce one redefined version» both effective, no redefinition > Problem name clash, must rename, get replication 21-17

Conflict Resolution Sharing 2 Other solutions» Make one of the versions deferred Other takes over > Could have intermediate class C' to defer > Better is to use undefine f class D inherit B C undefine f end... B C g» Different names join the solutions > Requires compatible signatures and semantics D class D inherit B C rename g as f undefine f end... 21-18

Conflict Resolution Replication f bf ++ B f A C Suppose a1 := instance of D» Then a1.f is ambiguous > could be either f or bf D Programmer must select the version class D inherit B C select f end... class D inherit B select bf end C... 21-19

Select Rule A class that inherits two or more different effective versions of a feature from a repeated ancestor and does not redefine them both, must include exactly one of them in a select clause» Use select all if that is desired 21-20

Genericity with Repeated Inheritance The type of any feature that is shared under the repeated inheritance rule, and the type of any of its arguments if it is a routine, may not be a generic parameter of the class from which the feature is repeatedly inherited class A[G] feature f : G end class B inherit A [INTEGER] A [REAL] end» Ambiguity as to the type for f in B.» Use renaming to get replication, if genericity is needed 21-21

Name Clashes Definition & Rule In a class obtained through multiple inheritance, a name clash occurs when two features inherited from different parents have the same final name A name clash makes the class invalid except in any of the following cases» The two features are inherited from a common ancestor and none has been redeclared from the version in that ancestor» Both features have compatible signatures and at least one of them is inherited in deferred form» Both features have compatible signatures and they are both redefined in the class > As one redefinition for the feature 21-22

Summary of Adaptation Clauses Eiffel adaptation clauses are in the following order. class B inherit A rename f1 as new_f1, f2 as new_f2, f3 as new_f3 export {A, B} new_f1, f4 undefine new_f3, f6 redefine new_f2, f5 select new_f2, f7 end 21-23