Example Test Questions for Inheritance

Size: px
Start display at page:

Download "Example Test Questions for Inheritance"

Transcription

1 2009 November 23 Example Test Questions for Inheritance Give and explain the type rule with genericity using an example method call. escribe constraint genericity. How is such genericity related to inheritance? Provide an example where constraint genericity is useful. When you redefine a, you can redefine the signature and body indepently. Explain why you need redefinition of each part and what are the constraints on redefinition. When you redefine a, there are two parts of a you can redefine indepently. Explain what they are, why you need redefinition of each part and what are the constraints on redefinition? What is the rule of change in the context of deciding between use and inheritance? Give three natural language definitions and their corresponding Eiffel class definitions that illustrate the choices in deciding between use and inheritance? When using multiple inheritance sharing and replication of attributes are the choices that are available. Using a ON diagram, give an example where sharing is not an option. Explain why sharing is not an option. When using multiple inheritance sharing and replication of attributes are the choices that are available. Using a ON diagram, give an example where sharing and replication are options. Explain why sharing is an option and how you get sharing. Explain why replication is an option and how you get replication. When using multiple inheritance some s may be joined. Using a ON diagram, give an example where join is an option and explain under what conditions join is possible. Explain what happens to the export status of inherited s in an heir. Why would you not normally build the QUEUE class from the RRY class using inheritance? In Eiffel, inherited functions can be redefined as attributes but not vice versa. Why not? onsider the following inheritance diagram. What problems can arise and how can they resolved? You are not required to solve all problems simultaneously, just describe the various problems and their resolution.

2 2009 November 23 Sample Inheritance Test Questions Page 2 of 9 f, h, j ++ f g f g 13. onsider the following ON diagram. + PERSON work : T TEHER STUENT work ++ : T T 14. Give and explain one variation of the Eiffel inheritance and adaptation clauses for the class T that permit sharing the common. Give and explain a different variation of the Eiffel inheritance and adaptation clauses for the class T that permit sharing the common. Give and explain the Eiffel inheritance and adaptation clauses for the class T that permit replicating the common Using an example, explain static and dynamic types of an entity and how they relate. Explain polymorphism and dynamic binding.

3 2009 November 23 Sample Inheritance Test Questions Page 3 of Explain why the creation status of a in the parent has no bearing on the creation status of that in an heir. Explain the difference between renaming and redefining an inherited. Is the following inheritance scenario correct? If yes, state why. If not, state what is the problem and how it can be resolved? class [G] class inherit f: G [REL] [STRING] Given following class hierarchy: PERSON EMPLOYEE STUENT T and declaration and instructions: p : PERSON; e: EMPLOYEE; s : STUENT; t1, t2 : T create p.make( ); create s.make( ); create t1.make( ) are the following instructions valid? Give a reason for your answer. create PERSON t2.make( ) create T e.make( ) p := t1 s?= p 19. In the following design, the class STUENT_TRINEE is missing adaptation or other Eiffel inheritance statements, thereby introducing inconsistencies and errors. There is additional missing program text. Identify what is missing and supply Eiffel program text to correct the program. ssume the given rename and redefine statements are correct. class PERSON eat (what: FOO) is print ("I eat sometimes!") sleep is print ("I sleep sometimes!") play is print ("I play sometimes!") -- class PERSON class EMPLOYEE inherit PERSON rename play as work redefine eat eat (what: STEK) is class STUENT inherit PERSON rename play as study redefine eat eat (what: SNWIH) is print ("I eat sandwich!") -- class STUENT class STUENT_TRINEE inherit STUENT redefine work, eat EMPLOYEE redefine eat

4 2009 November 23 Sample Inheritance Test Questions Page 4 of 9 print ("I eat steak!") -- class EMPLOYEE class FOO -- class FOO eat (what: STEK_SNWIH) is print ("I eat well!") -- class STUENT_TRINEE class STEK inherit FOO -- class STEK class SNWIH inherit FOO -- class SNWIH The creation inheritance rule states that the creation status of a in the parent has no bearing on its creation status in an heir. Explain what this means and why it is a reasonable rule. In the following diagram class inherits two versions of "f": one from and a redefined version from. ased on whether "f " is deferred or not, discuss the problems associated with "f" in and how they can be resolved. f f onsider the following program text. class ITY the_city: ITY is once Result := urrent invariant lonely_city: the_city = urrent -- class ITY class LONON inherit ITY -- class LONON class TORONTO inherit ITY -- class TORONTO ssuming the class invariant is checked, es the execution of the following statements lead to any assertion violation in Eiffel? Justify your answer. city1, city2 : ITY toronto: TORONTO lonn: LONON

5 2009 November 23 Sample Inheritance Test Questions Page 5 of 9 create toronto create lonn city1 := lonn.the_city city2 := toronto.the_city 23. ssume class LONON, from part, is modified as defined below. raw memory diagrams for objects created as a result of execution of the set of statements in Part above. ssume assertions are turned on. class LONON inherit ITY redefine the_city the_city: LONON is once Result := urrent -- class LONON onsider the following program text. class THING the_thing: THING is once Result := urrent invariant only_thing: the_thing = urrent class ETTER inherit SOMETHING class WORSE inherit SOMETHING ssuming the class invariant is checked, es the execution of the following statements lead to any assertion violation in Eiffel? Justify your answer. thing_1, thing_2 : THING the_worse: WORSE the_better: ETTER create the_worse create the_better thing_1 := the_better.the_thing thing_2 := the_worse.the_thing ssume class ETTER, from part, is modified as defined below. raw memory diagrams for objects created as a result of execution of the set of statements in Part above. ssume assertions are turned on. class ETTER inherit SOMETHING redefine the_thing the_thing: ETTER is once Result := urrent 24. The following hierarchy defines players in baseball.

6 2009 November 23 Sample Inheritance Test Questions Page 6 of 9 ssume that PITHER introduces a starts (indicating the number of games the pitcher started), while the class PLYER introduces a deferred display that is implemented by the subtypes. LOSER is a special kind of pitcher, one who always finishes games. Show the inheritance clause for LOSER, including and redefine and export clauses. Supose you wanted to modify this design to handle designated hitters, players who only hit and not play infield or outfield. What changes would you suggest to the hierarchy? In the National League, pitchers also hit. Show modifications to the inheritance hierarchy that would take into account National League pitchers and merican League pitchers (who not hit). team has a set of players. Sketch an Eiffel implementation of a routine that would display all the players on a team. 25. Suppose you wrote the following four classes but you haven t tried to compile them. onsider how the class ELT can handle possible name clashes. deferred class LPH one is print( alpha one ) two is print( alpha two ) three is print( alpha three ) four is deferred deferred class ET inherit LPH redefine two two is print( beta two )

7 2009 November 23 Sample Inheritance Test Questions Page 7 of 9 class HRLIE inherit LPH redefine two, three two is print( charlie two ) three is print( charlie three ) four is print( charlie four ) class ELT inherit ET rename one as beta_one HRLIE rename one as charlie_one select four The answers to the following questions require either a yes or no, as appropriate, and must give a rationale that references appropriate rules or principles. yes or no without a rationale receives a zero grade. 26. Is it necessary for class ELT to include the procedure one in a rename clause? If so, please explain why. If not, please explain why not. Is it acceptable for class ELT to not refer to the procedure two in a rename, redefine, undefine, or select clause? If so, you must explain why. If not, you must explain why not, and describe one way in which the problem can be resolved. Is it acceptable for class ELT to not refer to the procedure three in a rename, redefine, undefine, or select clause? If so, you must explain why. If not, you must explain why not, and describe one way in which the problem can be resolved. Is it necessary for class ELT to refer to the procedure four in a select clause? If so, please explain why. If not, please explain why not. onsider the following class hierarchy and program text. p : PERSON; t : TEHER; s : STUENT; ta1, ta2 : T create p.make( ) create s.make( ) create ta1.make( ) 27. For each of the following instructions state whether or not the instruction is valid and give the reason why. 1) create {PERSON} ta2.make( ) 2) create {T} t.make( ) 3) p := ta1 4) s?= p ) We learned that software modeling is difficult: by changing our view point we can rephrase an "isa" relationship to a "has-a" relationship. For example "every software engineer is an engineer" can be rephrased as "every software engineer has an engineer component", therefore changing "inheritance"

8 2009 November 23 Sample Inheritance Test Questions Page 8 of relationship to "client-supplier". iscuss what criteria can be used, in such situations, to decide whether is-a or has-a is the most appropriate relation for the chosen entities. ) We have two relations between classes: client-supplier and inheritance. ompare these two relations in terms of reuse, information hiding and protection against change. That is to say which one of these relationships allow for reuse of services provided by a class, which allows for information hiding, and which protects a class against change. Justify your answers. ) In Eiffel a descent can redefine a function with no argument into an attribute, but not vice versa. First explain why it is not possible to redefine an attribute into a function. Then explain how a descent defining a function into an attribute should handle the postcondition of that function. With multiple inheritance sharing and replication of s are the choices that are available. Using a ON diagram, give an example where sharing and replication are options. Explain why sharing is an option and give the Eiffel program text that enables sharing. Explain why replication is an option and give the Eiffel program text that enables replication.. With multiple inheritance sharing and replication of attributes are the choices that are available. Using a ON diagram, give an example where sharing is not an option. Explain why sharing is not an option. nswer the following questions with respect to the program text given at the of the question. What would be the class invariant for class? Will the class invariant be satisfied immediately after creating an instance of create a.make. Justify your answer completely and in detail. ssume that all assertions are changed to true, what would be the result of executing the program text in the ROOT_LSS. Justify your answer completely and in detail. Is the redefinition of the printa in class correct. Justify your answer in detail by using the complete pre and post conditions to justify your conclusion. class creation make x : INTEGER y : INTEGER make is x := 2 ; y := 5 printa( a : INTEGER) is require y > x class inherit rename printa as c_print redefine uble creation make printa( a : INTEGER) is require true class ROOT_LSS creation make a : ; b : c : ; d : make is!! a.make ;!!b.make

9 2009 November 23 Sample Inheritance Test Questions Page 9 of 9 io.put_string("in a is: ") io.put_integer(a) ensure y - x > 0 uble : INTEGER is require y > 2 result := 2 * y + x ensure result > y + x invariant x > 1 io.put_string("in a is: ") io.put_integer(a) ensure true uble : INTEGER is require else y > 0 result := x + y - x*y ensure then result > x + y invariant y >= 5!! c.make ;!!d.make a.printa(a.uble) d := a d.printa(a.uble) class inherit redefine printa, make creation make z : INTEGER make is precursor ; z := -4 printa( a : INTEGER) is require else x > 0 io.put_string("in a is: ") io.put_integer(a) ensure then true invariant z < x or z > y y 5 > x class inherit rename printa as b_print redefine uble, make undefine make redefine uble select c_print creation make make is precursor uble := z + x + y uble : INTEGER invariant??? Eiffel has four mechanisms for adaptation. escribe and give an example of each one.. What is the rule of change in the context of deciding between use and inheritance?. Give three natural language definitions and their corresponding Eiffel class definitions that illustrate the choices in deciding between use and inheritance?

Multiple & Repeated! Inheritance!

Multiple & Repeated! Inheritance! 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

More information

Multiple & Repeated Inheritance

Multiple & Repeated Inheritance 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

More information

Introduction to Eiffel

Introduction to Eiffel Introduction to Eiffel Martin Nordio, Christian Estler ETH Zurich Distributed Software Engineering Lab 1 Overview Part 1: Language Constructs Ø Basics: definition, if then else, expressions, loops and

More information

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

Introduction to Programming. Lecture 20: More about inheritance. Multiple inheritance. Composite figures. Bertrand Meyer 1 2 Introduction to Programming ertrand Meyer Lecture 20: More about ance Last revised 10 January 2004 Multiple ance 3 Simpler examples of multiple ance 4 llow a class to have two or more parents. UNIVERSITY_

More information

Lecture 13: Introduction to inheritance and genericity

Lecture 13: Introduction to inheritance and genericity Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 13: Introduction to inheritance and genericity On the menu for today (& next

More information

Assignment 7: Inheritance

Assignment 7: Inheritance Assignment 7: Inheritance ETH Zurich Hand-out: 11 December 2006 Due: 19 December 2006 Calvin and Hobbes c Bill Watterson 1 Dynamic exercise Goal Understand the effects of dynamic binding. Summary Have

More information

Software Architecture 4. July 2005

Software Architecture 4. July 2005 Chair of Software Engineering Bertrand Meyer Software Architecture 4. July 2005 Name, First name:... I confirm with my signature, that I was able to take this exam under regular conditions and that I have

More information

Einführung in die Programmierung Introduction to Programming

Einführung in die Programmierung Introduction to Programming Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7 News (Reminder) Mock exam next week! Ø Attance is highly recommed

More information

BON Business Object Notation Based on slides by Prof. Paige

BON Business Object Notation Based on slides by Prof. Paige BON Business Object Notation Based on slides by Prof. Paige 17-1 What is it? Notation for modeling object oriented software» Static: specifies classes, class relationships» Dynamic: behavioural properties

More information

Patterns Example Exam Questions

Patterns Example Exam Questions 2014 November 27 Patterns Example Exam Questions 1.. Using on, give a generic static diagram of the pattern and include relevant interface s. 2. 3.. Give a scenario and object communication diagram

More information

Eiffel: Analysis, Design and Programming

Eiffel: Analysis, Design and Programming Eiffel: Analysis, Design and Programming Bertrand Meyer (Nadia Polikarpova) Chair of Software Engineering - 8 - Inheritance 2 Overview Basics Redefinition Polymorphism and dynamic binding Inheritance and

More information

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

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

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

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

More information

Universe Type System for Eiffel. Annetta Schaad

Universe Type System for Eiffel. Annetta Schaad Universe Type System for Eiffel Annetta Schaad Semester Project Report Software Component Technology Group Department of Computer Science ETH Zurich http://sct.inf.ethz.ch/ SS 2006 Supervised by: Dipl.-Ing.

More information

Inheritance and object compatibility

Inheritance and object compatibility Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not the other way around Examples: reference/pointer can

More information

Chapter 8: Class and Method Design

Chapter 8: Class and Method Design Chapter 8: Class and Method Design Objectives Become familiar with coupling, cohesion, and connascence. Be able to specify, restructure, and optimize object designs. Be able to identify the reuse of predefined

More information

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

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

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

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון Overriding עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap A method in a child class overrides a method in the parent class if it has the same name and type signature: Parent void method(int,float)

More information

Object-Oriented Software Construction

Object-Oriented Software Construction 1 Object-Oriented Software Construction Bertrand Meyer 2 Lecture 21: Typing issues, covariance The America Conjecture 3 (Pierre America at TOOLS Europe 1990) One can have at most two of the three properties

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

More information

Eiffel: Analysis, Design and Programming. ETH Zurich, September-December Exception handling

Eiffel: Analysis, Design and Programming. ETH Zurich, September-December Exception handling Eiffel: Analysis, Design and Programming ETH Zurich, September-December 2008-6- Exception handling What is an exception? An abnormal event Not a very precise definition Informally: something that you don

More information

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

Multiple Inheritance עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון Multiple Inheritance עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will investigate some of the logical problems that can arise when a language allows a child class to

More information

Software Development. Modular Design and Algorithm Analysis

Software Development. Modular Design and Algorithm Analysis Software Development Modular Design and Algorithm Analysis Precondition and Postcondition To create a good algorithm, a programmer must be able to analyse a precondition (starting state) and a postcondition

More information

Inheritance Readings: OOSCS2 Chapters 14 16

Inheritance Readings: OOSCS2 Chapters 14 16 Inheritance Readings: OOSCS2 Chapters 14 16 EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG Aspects of Inheritance Code Reuse Substitutability Polymorphism and Dynamic Binding [ compile-time type checks

More information

What s Conformance? Conformance. Conformance and Class Invariants Question: Conformance and Overriding

What s Conformance? Conformance. Conformance and Class Invariants Question: Conformance and Overriding Conformance Conformance and Class Invariants Same or Better Principle Access Conformance Contract Conformance Signature Conformance Co-, Contra- and No-Variance Overloading and Overriding Inheritance as

More information

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

Multiple Inheritance לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון Multiple Inheritance לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון 22 Roadmap In this chapter we will investigate some of the logical problems that can arise when a language allows a child class

More information

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

The COURSE Class. class COURSE. create -- Declare commands that can be used as constructors make. feature -- Attributes title: STRING fee: REAL The COURSE Class Inheritance Readings: OOSCS2 Chapters 14 16 EECS3311: Software Design Fall 2017 CHEN-WEI WANG class COURSE create -- Declare commands that can be used as constructors make feature -- Attributes

More information

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

JOURNAL OF OBJECT TECHNOLOGY

JOURNAL OF OBJECT TECHNOLOGY JOURNAL OF OBJECT TECHNOLOGY Online at www.jot.fm. Published by ETH Zurich, Chair of Software Engineering JOT, 2002 Vol. 1, no. 4, September-October 2002 Eiffel Assertions and the External Structure of

More information

A Eiffel: The Essentials

A Eiffel: The Essentials A Eiffel: The Essentials This appix addresses people who are familiar with the object-oriented approach but not know Eiffel very well. It introduces all the concepts needed to understand the core of this

More information

10 Feature adaptation

10 Feature adaptation 10 Feature adaptation Draft 5.02.00-0, 15 August 2005 (Santa Barbara). Extracted from ongoing work on future third edition of Eiffel: The Language. Copyright Bertrand Meyer 1986-2005. Access restricted

More information

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

Singleton Pattern Creational. » Ensure a class has only one instance» Provide a global point of access Singleton Pattern Creational Intent» Ensure a class has only one instance» Provide a global point of access Motivation Some classes must only have one instance file system, window manager Applicability»

More information

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

Eiffel: An Advanced Introduction. Alan A. Snyder Brian N. Vetter Eiffel: An Advanced Introduction Alan A. Snyder Brian N. Vetter Introduction - Welcome To Eiffel Table of Contents 1 - Basic Concepts and Syntax 1.0 Classes and Objects 1.1 References 1.2.1 Declaring Expanded

More information

- 9/10 - Inheritance

- 9/10 - Inheritance -9/10 - Inheritance Inheritance in Eiffel Class may redefine ( override ) inherited features. Redefinition is explicit In line with Uniform Access principle, may redefine inherited function into attribute.

More information

Design by Contract in Eiffel

Design by Contract in Eiffel Design by Contract in Eiffel 2002/04/15 ctchen@canthink.com.com.tw.tw Reference & Resource Bertrand Meyer, Object-Oriented Oriented Software Construction 2nd,, 1997, PH. Bertrand Meyer, Eiffel: The Language,,

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

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

Programming Languages. Benjamin J. Keller Department of Computer Science, Virginia Tech Programming Languages Eiffel Benjamin J. Keller Department of Computer Science, Virginia Tech Programming Languages Eiffel 2 Overview Classes and Objects Builtin types, constants and operations Expressions,

More information

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. Ch. 14: Inheritance

More information

System Concepts and Architecture. Rose-Hulman Institute of Technology Curt Clifton

System Concepts and Architecture. Rose-Hulman Institute of Technology Curt Clifton System Concepts and Architecture Rose-Hulman Institute of Technology Curt Clifton Data Model A set of concepts to describe Database structure Basic operations on the data Categories of Data Models Conceptual

More information

Object-Oriented Concepts and Design Principles

Object-Oriented Concepts and Design Principles Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Programming Exercise 14: Inheritance and Polymorphism

Programming Exercise 14: Inheritance and Polymorphism Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.

More information

Lecture 14: More Inheritance & Genericity

Lecture 14: More Inheritance & Genericity Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer October 2006 February 2007 MP1 Lecture 14: More Inheritance & Genericity 2 Genericity:

More information

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

Major Differences between Java and C++ Programming in C++ Multiple Inheritance Programming in C++ Session 7 - Multiple Inheritance Dr Christos Kloukinas City, UoL http://staff.city.ac.uk/c.kloukinas/cpp (slides originally produced by Dr Ross Paterson) Major Differences between Java

More information

CSC Advanced Object Oriented Programming, Spring Specification

CSC Advanced Object Oriented Programming, Spring Specification CSC 520 - Advanced Object Oriented Programming, Spring 2018 Specification Specification A specification is an unambiguous description of the way the components of the software system should be used and

More information

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

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis? Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2005 P. N. Hilfinger Project #2: Static Analyzer for Pyth Due: Wednesday, 6 April

More information

The Eiffel language. Slides partly based on :

The Eiffel language. Slides partly based on : The Eiffel language Slides partly based on : http://se.inf.ethz.ch/courses/2015b_fall/eprog/english_index.html Eiffel, in brief Procedural, object-oriented programming language created by Bertrand Meyer

More information

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects,

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects, Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects, Classes, Class Diagrams Values and Attributes Operations

More information

Assignment 4: Object creation

Assignment 4: Object creation Assignment 4: Object creation ETH Zurich Hand-out: 15 November 2005 Due: 22 November 2005 Copyright FarWorks, Inc. Gary Larson 1 Summary Today you are going to write your rst stand-alone program. Please

More information

Solution 7: Inheritance and polymorphism

Solution 7: Inheritance and polymorphism Solution 7: Inheritance and polymorphism ETH Zurich 1 Polymorphism and dynamic binding Task 1 create warrior.make ( Thor ) warrior.level up Does the code compile? Yes Thor is now a level 2 warrior. Task

More information

Solution 3: Of objects and features

Solution 3: Of objects and features Solution 3: Of objects and features ETH Zurich 1 Classes vs. objects There is no unique solution. Sample answers: 1.1 A class can be viewed as a software module (a piece of source code that contains descriptions

More information

ETHZ D-INFK Final Exam Booklet

ETHZ D-INFK Final Exam Booklet ETHZ D-INFK Booklet Date: 15 December 2009 Surname, first name:... Student number:... I confirm with my signature, that I was able to take this exam under regular circumstances and that I have read and

More information

In-Class Exercises. ETH Zurich. November

In-Class Exercises. ETH Zurich. November In-Class Exercises ETH Zurich November 28 2012 1 Contracts ETH students recently designed a special kind of oven for cooking potatoes. Here are some facts about such an oven: each oven is equipped with

More information

Inheritance. OOP: Inheritance 1

Inheritance. OOP: Inheritance 1 Inheritance Reuse Extension and intension Class specialization and class extension Inheritance The protected keyword revisited Inheritance and methods Method redefinition An widely used inheritance example

More information

Inheritance and Substitution (Budd chapter 8, 10)

Inheritance and Substitution (Budd chapter 8, 10) Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various

More information

PROGRAMMING LANGUAGE 2

PROGRAMMING LANGUAGE 2 31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It

More information

Inheritance. Finally, the final keyword. A widely example using inheritance. OOP: Inheritance 1

Inheritance. Finally, the final keyword. A widely example using inheritance. OOP: Inheritance 1 Inheritance Reuse of code Extension and intension Class specialization and class extension Inheritance The protected keyword revisited Inheritance and methods Method redefinition The composite design pattern

More information

[ L5P1] Object-Oriented Programming: Advanced Concepts

[ L5P1] Object-Oriented Programming: Advanced Concepts [ L5P1] Object-Oriented Programming: Advanced Concepts Polymorphism Polymorphism is an important and useful concept in the object-oriented paradigm. Take the example of writing a payroll application for

More information

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. QUIZ How

More information

Lecture 15: Generalization, Polymorphism and States. Copyright W. Howden 1

Lecture 15: Generalization, Polymorphism and States. Copyright W. Howden 1 Lecture 15: Generalization, Polymorphism and States Copyright W. Howden 1 Generalization Creation of super and subtype entities May be program and design classes, concepts, use cases, etc. For programs,

More information

Singleton Pattern Creational

Singleton Pattern Creational Singleton Pattern Creational Intent» Ensure a class has only one instance» Provide a global point of access Motivation Some classes must only have one instance file system, window manager Applicability»

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Test-Driven Development (TDD)

Test-Driven Development (TDD) Test-Driven Development (TDD) EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG DbC: Supplier DbC is supported natively in Eiffel for supplier: class ACCOUNT create make feature -- Attributes owner :

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database Extensions to SQL ODMG Object Model and the Object Definition Language ODL Object Database Conceptual

More information

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

UC Santa Barbara. CS189A - Capstone. Christopher Kruegel Department of Computer Science UC Santa Barbara CS189A - Capstone Christopher Kruegel Department of Computer Science http://www.cs.ucsb.edu/~chris/ Design by Contract Design by Contract and the language that implements the Design by Contract principles

More information

a correct statement? You need to know what the statement is supposed to do.

a correct statement? You need to know what the statement is supposed to do. Using assertions for correctness How can we know that software is correct? It is only correct if it does what it is supposed to do. But how do we know what it is supposed to do? We need a specification.

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I.

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I. y UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I Lab Module 7 CLASSES, INHERITANCE AND POLYMORPHISM Department of Media Interactive

More information

Introduction to Design Patterns

Introduction to Design Patterns Introduction to Design Patterns First, what s a design pattern? a general reusable solution to a commonly occurring problem within a given context in software design It s not a finished design that can

More information

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION c08classandmethoddesign.indd Page 282 13/12/14 2:57 PM user 282 Chapter 8 Class and Method Design acceptance of UML as a standard object notation, standardized approaches based on work of many object methodologists

More information

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107 A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Control flow in Eiffel

Control flow in Eiffel Announcements Assignment will be posted this week.» We ll make sure you have enough time to it! A little more Eiffel, Genericity and ADTs Week 3, Lecture 4 January 16 Section N Review What is the definition

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

Programming in C# Inheritance and Polymorphism

Programming in C# Inheritance and Polymorphism Programming in C# Inheritance and Polymorphism C# Classes Classes are used to accomplish: Modularity: Scope for global (static) methods Blueprints for generating objects or instances: Per instance data

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Conformance. Object-Oriented Programming Spring 2015

Conformance. Object-Oriented Programming Spring 2015 Conformance Object-Oriented Programming 236703 Spring 2015 1 What s Conformance? Overriding: replace method body in sub-class Polymorphism: subclass is usable wherever superclass is usable Dynamic Binding:

More information

The Dependent Delegate Dilemma

The Dependent Delegate Dilemma The Depent Delegate Dilemma Bertrand Meyer, ETH Zurich ABSTRACT A criticism of the object-oriented style of programming is that the notion of class invariant seems to collapse in non-trivial client-supplier

More information

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

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation CSE 452: Programming Languages Data Abstraction and Object-Orientation Previous Lecture Abstraction Abstraction is the elimination of the irrelevant and the amplification of the essential Robert C Martin

More information

Inheritance (Outsource: )

Inheritance (Outsource: ) (Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,

More information

More on Inheritance. Interfaces & Abstract Classes

More on Inheritance. Interfaces & Abstract Classes More on Inheritance Interfaces & Abstract Classes Java interfaces A Java interface is used to specify minimal functionality that a client requires of a server. A Java interface contains: method specifications

More information

Inheritance -- Introduction

Inheritance -- Introduction Inheritance -- Introduction Another fundamental object-oriented technique is called inheritance, which, when used correctly, supports reuse and enhances software designs Chapter 8 focuses on: the concept

More information

Chapter 11 Object and Object- Relational Databases

Chapter 11 Object and Object- Relational Databases Chapter 11 Object and Object- Relational Databases Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Outline Overview of Object Database Concepts Object-Relational

More information

1. Quality issues (5 points)

1. Quality issues (5 points) ETH Zurich Computer Science Course: Advanced Topics in Object Technology, by Bertrand Meyer Summer semester 2003 Exam (prepared by Karine Arnout) 2 July 2003 10:00 to 12:00 Name:.. Id-Nr:.. No notes, computers,

More information

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

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005 Wrapping a complex C++ library for Eiffel FINAL REPORT July 1 st, 2005 Semester project Student: Supervising Assistant: Supervising Professor: Simon Reinhard simonrei@student.ethz.ch Bernd Schoeller Bertrand

More information

Topics in Object-Oriented Design Patterns

Topics in Object-Oriented Design Patterns Software design Topics in Object-Oriented Design Patterns Material mainly from the book Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides; slides originally by Spiros Mancoridis;

More information

Generic Collection Class: Motivation (2) Use of Generic Parameters Iterator and Singleton Patterns

Generic Collection Class: Motivation (2) Use of Generic Parameters Iterator and Singleton Patterns Generic Collection Class: Motivation (2) Use of Generic Parameters Iterator and Singleton Patterns EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG ACCOUNT _STACK {NONE -- Implementation imp: ARRAY[

More information

Berkeley Scheme s OOP

Berkeley Scheme s OOP Page < 1 > Berkeley Scheme s OOP Introduction to Mutation If we want to directly change the value of a variable, we need a new special form, set! (pronounced set BANG! ). (set! )

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

OO is considered to be supported in three points which are usually symbolized as the three vertexes of a triangle: Encapsulació i ocultació

OO is considered to be supported in three points which are usually symbolized as the three vertexes of a triangle: Encapsulació i ocultació Object Orientation Its origin is placed at the beginning of the 70 s in a friendly environment project that Xerox Company developed in Palo lto with a team made up of lan Kay, dele Goldberg and Dan Ingalls.

More information

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

Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will start to investigate the concepts of inheritance and substitution: The intuitive and practical

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM Objectives Defining a wellformed method to check class invariants Using assert statements to check preconditions,

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract

More information

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

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Sung Hee Park Department of Mathematics and Computer Science Virginia State University September 18, 2012 The Object-Oriented Paradigm

More information

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1 OBJECT ORIENTED SIMULATION LANGUAGE OOSimL Reference Manual - Part 1 Technical Report TR-CSIS-OOPsimL-1 José M. Garrido Department of Computer Science Updated November 2014 College of Computing and Software

More information

Overloading, Type Classes, and Algebraic Datatypes

Overloading, Type Classes, and Algebraic Datatypes Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

More information

Introduction to Programming. Bertrand Meyer. Lecture 23: An example: undo-redo. The problem

Introduction to Programming. Bertrand Meyer. Lecture 23: An example: undo-redo. The problem 1 Introduction to Programming Bertrand Meyer Last revised 20 January 2004 2 Lecture 23: An example: un-re The problem 3 Enabling users of an interactive system to cancel the effect of the last command.

More information

Implementing a VSOP Compiler. March 20, 2018

Implementing a VSOP Compiler. March 20, 2018 Implementing a VSOP Compiler Cyril SOLDANI, Pr. Pierre GEURTS March 20, 2018 Part III Semantic Analysis 1 Introduction In this assignment, you will do the semantic analysis of VSOP programs, according

More information