Chair of Software Engineering ATOT - Lecture 9, 30 April 2003 1 Advanced Topics in Object Technology Bertrand Meyer.

Slides:



Advertisements
Similar presentations
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Advertisements

Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Exercise Session 1: Eiffel Introduction.
Java Review Interface, Casting, Generics, Iterator.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 3: Abstract Data Types.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 18: Topological sort Part 1:
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session November 2008.
Image Indexing and Retrieval using Moment Invariants Imran Ahmad School of Computer Science University of Windsor – Canada.
Inheritance. class RECTANGLE inherit POLYGON RECTANGLE includes features of POLYGON r: RECTANGLE; p: POLYGON Polymorphism p := r -- legal assignment Dynamic.
Ceg860 (Prasad)L13MI1 Multiple Inheritance DAG Class Structure : Directed Acyclic Graph.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
1 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Chair of Software Engineering OOSC Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Design by Contract. Specifications Correctness formula (Hoare triple) {P} A {Q} – A is some operation (for example, a routine body) – P and Q are predicates.
Chair of Software Engineering OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 8: More on inheritance.
Chair of Software Engineering ATOT - Lecture 24, 25 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 17: Topological Sort Algorithm.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
Chair of Software Engineering ATOT - Lecture 12, 12 May Advanced Topics in Object Technology Bertrand Meyer.
Principles of Object-Oriented Software Development The language Eiffel.
Chair of Software Engineering ATOT - Lecture 8, 28 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 6 7 October 2008.
Chair of Software Engineering OOSC - Lecture 4 1 Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Lecture 21 1 Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 18: Undo/Redo.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 9: Contracts and Inheritance (based on work with.
Eiffel: Analysis, Design and Programming Bertrand Meyer Chair of Software Engineering.
Chair of Software Engineering 1 Introduction to Programming Exercise Session Week 9 M. Piccioni 17/18 November 2008.
Chair of Software Engineering ATOT - Lecture 11, 7 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 23, 23 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
Chair of Software Engineering ATOT - Lecture 3, 7 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 14, 19 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 16: Topological sort Part 1:
Chair of Software Engineering ATOT - Lecture 15, 21 May Advanced Topics in Object Technology Bertrand Meyer.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
Chair of Software Engineering OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 7: Inheritance.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering ATOT - Lecture 7, 23 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 20: Multiple inheritance.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
Eiffel: Analysis, Design and Programming Bertrand Meyer (Nadia Polikarpova) Chair of Software Engineering.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Chair of Software Engineering ATOT - Lecture 22, 18 June Advanced Topics in Object Technology Bertrand Meyer.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
1 Software Architecture Bertrand Meyer ETH Zurich, March-July 2009 Lecture 11: More patterns: Bridge, Composite, Decorator, Façade, Flyweight.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Department of Computer Science, York University Object Oriented Software Construction 14/10/ :15 AM 0 COSC3311 – Software Design Inheritance and.
More About Classes Ranga Rodrigo. Information hiding. Copying objects.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Einführung in die Programmierung Introduction to Programming Prof. Dr
Inheritance and Polymorphism OOSC2 chapters 14 and parts of 15-17
Computer Graphics Matrix Hierarchies / Animation
Presentation transcript:

Chair of Software Engineering ATOT - Lecture 9, 30 April Advanced Topics in Object Technology Bertrand Meyer

Chair of Software Engineering ATOT - Lecture 9, 30 April Lecture 9: Inheritance

Chair of Software Engineering ATOT - Lecture 9, 30 April Typing vs. binding  What do we know about the feature to be called?  Static typing: At least one  Dynamic binding: The right one  Example: my_aircraft.lower_landing_gear

Chair of Software Engineering ATOT - Lecture 9, 30 April Example hierarchy AIRCRAFT * PLANE * COPTER * BOEINGAIRBUS A_320 B_747B_737 B_747_400 * deferred + effected ++ redefined lower_landing_gear* lower_landing_gear++ lower_landing_gear+

Chair of Software Engineering ATOT - Lecture 9, 30 April (After Barry W. Boehm) RequirementsDesignCodeDevelopmentAcceptanceOperation test SMALL PROJECTS LARGE PROJECTS

Chair of Software Engineering ATOT - Lecture 9, 30 April Multiple inheritance  A class may have two or more parents.  What not to use as an elementary example: TEACHING_ASSISTANT inherits from TEACHER and STUDENT. TEACHERSTUDENT TEACHING_ ASSISTANT

Chair of Software Engineering ATOT - Lecture 9, 30 April The teaching assistant example  This is in fact a case of repeated inheritance: TEACHERSTUDENT TEACHING_ ASSISTANT UNIVERSITY_ PERSON id ?? ????

Chair of Software Engineering ATOT - Lecture 9, 30 April Common examples of multiple inheritance  Combining separate abstractions:  Restaurant, train car  Calculator, watch  Plane, asset

Chair of Software Engineering ATOT - Lecture 9, 30 April Multiple inheritance: Combining abstractions COMPARABLENUMERIC STRINGCOMPLEX INTEGER REAL DOUBLE **

Chair of Software Engineering ATOT - Lecture 9, 30 April Multiple inheritance: Nested windows  ‘‘Graphical’’ features: height, width, change_height, change_width, xpos, ypos, move...  ‘‘Hierarchical’’ features: superwindow, subwindows, change_subwindow, add_subwindow... class WINDOW inherit RECTANGLE TREE [WINDOW] feature... end

Chair of Software Engineering ATOT - Lecture 9, 30 April Multiple inheritance: Composite figures A composite figure Simple figures

Chair of Software Engineering ATOT - Lecture 9, 30 April Defining the notion of composite figure FIGURE LIST [FIGURE] COMPOSITE_ FIGURE * display hide rotate move … count put remove …

Chair of Software Engineering ATOT - Lecture 9, 30 April Defining the notion of composite figure through multiple inheritance FIGURE LIST [FIGURE] COMPOSITE_ FIGURE * OPEN_ FIGURE CLOSED_ FIGURE SEGMENT POLYLINE POLYGON ELLIPSE RECTANGLE SQUARE CIRCLE TRIANGLE … perimeter+ perimeter* perimeter++ perimeter+ diagonal …

Chair of Software Engineering ATOT - Lecture 9, 30 April A composite figure as a list start item forthafter

Chair of Software Engineering ATOT - Lecture 9, 30 April Composite figures class COMPOSITE_FIGURE inherit FIGURE redefine display, move, rotate,... end LIST [FIGURE] feature display is -- Display each constituent figure in turn. do from start until after loop item.display forth end end... Similarly for move, rotate etc.... end

Chair of Software Engineering ATOT - Lecture 9, 30 April Complex figures  Note: a simpler form of procedures display, move etc. can be obtained through the use of iterators.  Exercise: Use agents for that purpose.

Chair of Software Engineering ATOT - Lecture 9, 30 April Name clashes under multiple inheritance A C foo B

Chair of Software Engineering ATOT - Lecture 9, 30 April Resolving name clashes A C foo B rename foo as fogrename foo as zoo

Chair of Software Engineering ATOT - Lecture 9, 30 April Resolving name clashes (cont’d) class C inherit A rename foo as fog end B rename foo as zoo end feature...

Chair of Software Engineering ATOT - Lecture 9, 30 April Results of renaming a1: A b1: B c1: C... c1.fog c1.zoo a1.foo b1.foo Invalid: a1.fog, a1.zoo, b1.zoo, b1.fog, c1.foo

Chair of Software Engineering ATOT - Lecture 9, 30 April Another application of renaming  Provide locally better adapted terminology.  Example: child (TREE); subwindow (WINDOW).

Chair of Software Engineering ATOT - Lecture 9, 30 April The marriage of convenience class ARRAYED_STACK [G] inherit STACK [G] ARRAY [G] feature... end class LINKED_STACK [G] inherit STACK [G] LINKED_LIST [G] feature... end

Chair of Software Engineering ATOT - Lecture 9, 30 April The need for deferred classes  In the scheme seen earlier: f: FIGURE; c: CIRCLE; p: POLYGON... create c.make (...); create p.make (...)... if... then f := c else f := p end... f.move (...); f.rotate (...); f.display (...);...  How do we ensure that a call such as f.move (...) is valid even though there is no way to implement a general-ee- purpose feature move for class FIGURE?

Chair of Software Engineering ATOT - Lecture 9, 30 April Deferred classes deferred class FIGURE feature move (v: VECTOR) is deferred end rotate (a: ANGLE; p: POINT) is deferred end... display, hide,... end Not permitted: create f...

Chair of Software Engineering ATOT - Lecture 9, 30 April Example hierarchy FIGURE * OPEN_ FIGURE * CLOSED_ FIGURE * SEGMENTPOLYLINEPOLYGONELLIPSE CIRCLE RECTANGLETRIANGLE SQUARE extent* barycenter* … display* rotate … perimeter* perimeter+ perimeter++ diagonal... perimeter++

Chair of Software Engineering ATOT - Lecture 9, 30 April Deferred classes and features  A feature is either deferred or effective.  To effect a inherited feature (deferred in the parent) is to make it effective. No need for redefine clause.  Like a feature, a class is either deferred or effective.  A class is deferred if it has at least one deferred feature (possibly coming from an ancestor) that it does not effect. It is effective otherwise.  A deferred class may not be instantiated.  BUT: A deferred class may have assertions (in particular, a deferred routine may have a precondition and a postcondition, and the class may have a class invariant).

Chair of Software Engineering ATOT - Lecture 9, 30 April Deferred classes  Compare with Ada-Modula 2-Java interface/body separation:  May contain both deferred and non-deferred elements.  More than one implementation is possible.  Formal semantic specification (assertions).

Chair of Software Engineering ATOT - Lecture 9, 30 April Table variants TABLE * SEQUENTIAL_ TABLE * LINKED_ TABLE + ARRAY_ TABLE + FILE_ TABLE +

Chair of Software Engineering ATOT - Lecture 9, 30 April Don’t call us, we’ll call you deferred class SEQUENTIAL_TABLE [G] inherit TABLE [G] feature has (x: G): BOOLEAN is -- Does x appear in table? do from start until after or else equal (item, x) loop forth end Result := not after end

Chair of Software Engineering ATOT - Lecture 9, 30 April SEQUENTIAL_TABLE (cont’d) forth is require not after deferred ensure position = old position + 1 end start is deferred ensure empty or else position = 1 end

Chair of Software Engineering ATOT - Lecture 9, 30 April SEQUENTIAL_TABLE (end) position: INTEGER is deferred end... empty, found, after,... invariant 0 <= position position <= size + 1 empty implies (after or before) end

Chair of Software Engineering ATOT - Lecture 9, 30 April Descendant implementations TABLE * SEQUENTIAL_ TABLE * LINKED_ TABLE + ARRAY_ TABLE + FILE_ TABLE + has+ forth* item* start* forth+ item+ start+ after+ forth+ item+ start+ after+ forth+ item+ start+ after+ after* has*

Chair of Software Engineering ATOT - Lecture 9, 30 April Descendant implementations (cont’d) SEQUENTIAL_ TABLE * LINKED_ TABLE + ARRAY_ TABLE + FILE_ TABLE + has+ forth* item* start* forth+ item+ start+ after+ forth+ item+ start+ after+ forth+ item+ start+ after+ after*

Chair of Software Engineering ATOT - Lecture 9, 30 April Implementation variants Array Linked list File startforthafterfound (x) c := first_cell rewind i := 1 c := c.right i := i + 1 readend_of_file c := Void f = x c.item = x i > countt [i] = x

Chair of Software Engineering ATOT - Lecture 9, 30 April End of lecture 9