Chair of Software Engineering OOSC - Summer Semester 2004 - 22 1 Object-Oriented Software Construction Bertrand Meyer.

Slides:



Advertisements
Similar presentations
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Advertisements

Eiffel: Analysis, Design and Programming Bertrand Meyer (Nadia Polikarpova) Chair of Software Engineering.
© 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 CAT calls (Changed Availability or Type) these slides contain advanced material and are optional.
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 1 Introduction to Programming Bertrand Meyer Exercise Session November 2008.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 7: SCOOP Type System (based on work with Piotr Nienaltowski)
Chair of Software Engineering Constants, once routines, and helper functions these slides contain advanced material and are optional.
Chair of Software Engineering Object-Oriented Software Construction Bertrand Meyer Lesson 16 Last update: 25 May 2004 An O-O design example.
Chair of Software Engineering OOSC Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 8: More on inheritance.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 15: Exception handling.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 4: Objects.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
Chair of Software Engineering Object-Oriented Software Construction Bertrand Meyer Lesson 21 Last update: 25 May 2004 Type issues, covariance and catcalls.
1 Advanced Material The following slides contain advanced material and are optional.
Typing Issues and LSP Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Readability (Java vs. Pearl) Catching errors.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 10: Project Presentation Ilinca.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 20: Some design principles.
Principles of Object-Oriented Software Development The language Eiffel.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 12: Design by Contract™
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 OOSC - Lecture 4 1 Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Covariance & anchored types 2 Covariance? Within the type system of a programming language, a typing rule or a type conversion operator is*:
Chair of Software Engineering OOSC - Lecture 21 1 Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 9: Contracts and Inheritance (based on work with.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 14: Presentation of EiffelStudio.
Eiffel: Analysis, Design and Programming Bertrand Meyer Chair of Software Engineering.
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 OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 7: Inheritance.
Chair of Software Engineering Object-Oriented Software Construction Bertrand Meyer Lecture 21: Agents and tuples.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 6:Computational Model (based on work with Piotr Nienaltowski)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 1 Introduction to Object-Oriented Programming.
Chair of Software Engineering ATOT - Lecture 7, 23 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 ATOT - Lecture 22, 18 June Advanced Topics in Object Technology Bertrand Meyer.
1 Chapter 14-2 Object- Oriented Software Development Dale/Weems.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Contracts for Concurrency - Contracts & Inheritance Aryabrata Basu University of Georgia.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Software Engineering in the Academy Bertrand Meyer IEEE Computer, May 2001.
Chapter 12 Support for Object oriented Programming.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Object-Oriented Programming Chapter Chapter
1 Unified Modeling Language, Version 2.0 Chapter 2.
Ceg860 (Prasad)L17IT1 Inheritance Techniques Subcontracting Anchored Types.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
A Survey of Object-Oriented Concept Oscar Nierstrasz.
© 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
Inheritance Techniques
Software Engineering in the Academy
Software Engineering in the Academy
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
Software Design Lecture : 14.
Einführung in die Programmierung Introduction to Programming Prof. Dr
Einführung in die Programmierung Introduction to Programming Prof. Dr
Einführung in die Programmierung Introduction to Programming Prof. Dr
Presentation transcript:

Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer

Chair of Software Engineering OOSC - Summer Semester Lecture 22: Typing issues, covariance

Chair of Software Engineering OOSC - Summer Semester Anchored declarations class DRIVER feature partner: like Current -- This driver’s alternate. share (other: like Current) is -- Choose other as alternate. require other /= Void do partner := other end end

Chair of Software Engineering OOSC - Summer Semester Client covariance (parallel hierarchies) DRIVER TRUCKER HEAVY_TRUCKER VEHICLE TRUCK HEAVY_TRUCK assigned assign

Chair of Software Engineering OOSC - Summer Semester More need for anchoring class DRIVER feature … partner, share as before… assigned: VEHICLE -- This driver’s assigned vehicle. assign (v: VEHICLE) is -- Choose v as assigned vehicle. require v /= Void do assigned := v end end

Chair of Software Engineering OOSC - Summer Semester Anchored declarations (client) class DRIVER feature … partner, share as before… assigned: VEHICLE -- This driver’s assigned vehicle. assign (v: like assigned) is -- Choose v as assigned vehicle. require v /= Void do assigned := v end end

Chair of Software Engineering OOSC - Summer Semester Polymorphism and the attachment rule  In an assignment x := y, or the corresponding argument passing, the base class of the type of y must be a descendant of the type of x.

Chair of Software Engineering OOSC - Summer Semester d1: DRIVER bd1: BIKER td1: TRUCKER Create a “trucker” and a “biker” objects: create bd1 create td1 d1 := td1 d1.share (bd1) Polymorphism and covariance

Chair of Software Engineering OOSC - Summer Semester d1: DRIVER bd1: BIKER td1: TRUCKER v1: VEHICLE truck1: TRUCK Create a “trucker” and a “biker” objects: create bd1 create td1 d1 := td1 v1 := truck1 d1.assign (v1) Polymorphism and client covariance

Chair of Software Engineering OOSC - Summer Semester Descendant hiding class RECTANGLE inherit POLYGON export {NONE} add_vertex end feature … invariant vertex_count = 4 end POLYGON RECTANGLE add_vertex

Chair of Software Engineering OOSC - Summer Semester Polymorphism and descendant hiding p: POLYGON r: RECTANGLE … create r … p := r … p.add_vertex (…)

Chair of Software Engineering OOSC - Summer Semester Genericity makes things worse! drivers: LIST [DRIVER] td1: TRUCKER bd1, bd2: BIKER truck1: TRUCK... drivers.extend (td1)... drivers.extend (bd1)... drivers.item (i).share (bd2) drivers.item(i).assign (truck1)

Chair of Software Engineering OOSC - Summer Semester Solutions to the catcall problem  Solution 1: Novariance  Solution 2: dynamic checks  Solution 3 (described in Eiffel: The Language): system ee-validity  Compute set of all potential types for each entity. This will for example disallow the combined presence of d1 := b1d1.share (t1)  because one of the possible types for d1 is BIKER.  Also useful for compiler optimization.  Disadvantage: requires (at least in a straightforward implementation) access to the entire system. Errors not easy to explain to users.

Chair of Software Engineering OOSC - Summer Semester Static typing is pessimistic (Pascal conventions) n: INTEGER n := 0.0 n := 1.0 n := 3.67 n := 3.67 – 3.67

Chair of Software Engineering OOSC - Summer Semester  An entity x is polymorphic if it satisfies one of the following properties:  It appears in an assignment x := y where y is of a different type or (recursively) polymorphic.  It is a formal routine argument.  It is an external function. Polymorphic entity

Chair of Software Engineering OOSC - Summer Semester Catcalls  A routine is a CAT (Changing Availability or Type) if some redefinition changes its export status or the type of one of its arguments.  A call is a catcall if some redefinition of the routine would make it invalid because of a change of export status or argument type.

Chair of Software Engineering OOSC - Summer Semester d1: DRIVER b1: BIKER t1: TRUCKER create b1 create t1 d1 := t1 … d1.share (t1) p: POLYGON r: RECTANGLE create r p := r p.add_vertex (…) Polymorphic catcalls

Chair of Software Engineering OOSC - Summer Semester Solution 4 (OOSC-2)  New type rule:  Polymorphic catcalls are invalid.  Note: can be checked incrementally; will be flagged either when adding a call or when adding a redefinition.  Not implemented by any compiler.

Chair of Software Engineering OOSC - Summer Semester Yet another solution (5)  Declare as cat any routine that either:  Has a redeclared argument type in a descendant  Has an anchored (like) argument  Has a more restricted export status in a descendant  Declare as poly any entity that can be polymorphic.  Prohibit:  Call of a cat routine on a poly target  Polymorphic assignment to target that is not poly  The problem: foresight! (Open-closed principle).

Chair of Software Engineering OOSC - Summer Semester End of lecture 22