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

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

SCOOP: Simple Concurrent Object-Oriented Programming Extend the pure, strongly typed, object-oriented language Eiffel with a general and powerful concurrency.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 3: Abstract Data Types.
2015/4/24Institute of Computer Software Nanjing University Typing, Inheritance and CATCALL 类型,继承以及 CATCALL 问题.
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 14: Container Data Structures.
Inheritance. class RECTANGLE inherit POLYGON RECTANGLE includes features of POLYGON r: RECTANGLE; p: POLYGON Polymorphism p := r -- legal assignment Dynamic.
1 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
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 ATOT - Lecture 10, 5 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 25, 30 June 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 - 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 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 17: Topological Sort Algorithm.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 14: Container Data Structures.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
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 Lecture 11: Design by Contract™
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.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
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 26, 30 June Advanced Topics in Object Technology Bertrand Meyer.
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 ATOT - Lecture 9, 30 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 16, 26 May Advanced Topics in Object Technology 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.
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 OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
Chair of Software Engineering ATOT - Lecture 14, 19 May Advanced Topics in Object Technology Bertrand Meyer.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
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 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.
Eiffel: Analysis, Design and Programming Bertrand Meyer (Nadia Polikarpova) Chair of Software Engineering.
Software Engineering Design by Contract 1 Design by Contract ™
Chair of Software Engineering ATOT - Lecture 22, 18 June Advanced Topics in Object Technology Bertrand Meyer.
Data Structures Data structures permit the storage of related data for use in your program. –Arrays.
Chapter 3 Introduction to Collections – Stacks Modified
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Click to edit Master text styles Stacks Data Structure.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Sections 3.4 Formal Specification
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Stacks and Queues.
CS313D: Advanced Programming Language
Chapter 8: Data Abstractions
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 13: Advanced inheritance mechanisms

Chair of Software Engineering OOSC - Summer Semester Deferred classes deferred class STACK [G] feature put (x: G) is -- Push x on top of stack. require not full deferred ensure item = x not empty end

Chair of Software Engineering OOSC - Summer Semester The STACK class (cont’d) remove is -- Pop top element of stack. require not empty deferred ensure not full count = old count – 1 end

Chair of Software Engineering OOSC - Summer Semester The STACK class (cont’d) full: BOOLEAN is -- Is there no room place for new items? deferred end empty: BOOLEAN is -- Is there no item? deferred end count: BOOLEAN is -- Number of items on stack deferred ensure Result >= 0 end

Chair of Software Engineering OOSC - Summer Semester The STACK class (cont’d) -- Not all features need be deferred! replace (x: G) is -- Replace top element of stack by x. require not empty do remove put (x) ensure not empty item = x count = old count end invariant not (full and empty) end

Chair of Software Engineering OOSC - Summer Semester Applications of deferred classes  Taxonomy  Library organization  Capturing common abstractions  Capturing common behaviors  “Don’t call us, we’ll call you”  Analysis  High-level architecture and design

Chair of Software Engineering OOSC - Summer Semester EiffelBase: Container structures CONTAINER * BOX * COLLECTION * TRAVERSABLE * FINITE * INFINITE * BOUNDED * UNBOUNDED * COUNTABLE * RESIZABLE * BAG * SET * HIERARCHICAL * LINEAR * TABLE * ACTIVE * INTEGER_ INTERVAL * BILINEAR * INDEXABLE * CURSOR_ STRUCTURE * DISPENSER * SEQUENCE * ARRAYSTRINGHASH_TABLESTACK * QUEUE * … …

Chair of Software Engineering OOSC - Summer Semester deferred class VAT inherit TANK feature in_valve, out_valve: VALVE fill is -- Fill the vat. require in_valve.open out_valve.closed deferred ensure in_valve.closed out_valve.closed is_full end empty, is_full, is_empty, gauge, maximum,... [Other features]... invariant is_full = (gauge >= 0.97 * maximum) and (gauge <= 1.03 * maximum) end Object-oriented analysis

Chair of Software Engineering OOSC - Summer Semester Indirect and direct repeated inheritance A B C D A D

Chair of Software Engineering OOSC - Summer Semester Repeated inheritance  Assume class TAXPAYER with attributes age: INTEGER address: STRING bank_account: ACCOUNT tax_id: INTEGER  and routines such as pass_birthday is do age := age + 1 end pay_taxes is... deposit_to_account (sum: INTEGER) is... TAXPAYER address tax_id pass_birthday age pay_taxes

Chair of Software Engineering OOSC - Summer Semester Repeated inheritance (cont’d)  Heirs may include SWISS_TAXPAYER and US_TAXPAYER. TAXPAYER address tax_id age pay_taxes pass_birthday US_ TAXPAYER SWISS_ TAXPAYER

Chair of Software Engineering OOSC - Summer Semester Repeated inheritance (cont’d)  The two above classes may in turn have a common heir: SWISS_US_TAXPAYER. TAXPAYER address tax_id pay_taxes pass_birthday US_ TAXPAYER SWISS_ TAXPAYER SWISS_US_ TAXPAYER

Chair of Software Engineering OOSC - Summer Semester Repeated inheritance issues  What happens with features inherited twice from the common ancestor TAXPAYER, such as address, age, tax_id, pass_birthday?

Chair of Software Engineering OOSC - Summer Semester The inheritance clause inherit SWISS_TAXPAYER rename address as swiss_address, tax_id as swiss_tax_id, pay_taxes as pay_swiss_taxes, bank_account as swiss_bank_account, deposit_to_account as deposit_to_swiss_account,... end US_TAXPAYER rename address as us_address, tax_id as us_tax_id, pay_taxes as pay_us_taxes, bank_account as us_bank_account, deposit_to_account as deposit_to_us_account,... end

Chair of Software Engineering OOSC - Summer Semester Sharing and replication  Features such as age and birthday, not renamed along any of the inheritance paths, will be shared.  Features such as tax_id, inherited under different names, will be replicated. TAXPAYER address tax_id pay_taxes pass_birthday US_ TAXPAYER SWISS_ TAXPAYER SWISS_US_ TAXPAYER address us_address tax_id us_tax_id pay_taxes pay_us_taxes address swiss_address tax_id swiss_tax_id pay_taxes pay_swiss_taxes

Chair of Software Engineering OOSC - Summer Semester The need for select  Assume there is a redefinition somewhere along the way: TAXPAYER address US_ TAXPAYER SWISS_ TAXPAYER SWISS_US_ TAXPAYER address++ address us_addressaddress swiss_address

Chair of Software Engineering OOSC - Summer Semester The need for select (cont’d)  A potential ambiguity arises because of polymorphism and dynamic binding: t: TAXPAYER s: SWISS_TAXPAYER u: US_TAXPAYER su: SWISS_US_TAXPAYER if... then t := s else t := su end... print (t.address)

Chair of Software Engineering OOSC - Summer Semester Removing the ambiguity class SWISS_US_TAXPAYER inherit SWISS_TAXPAYER rename address as swiss_address, tax_id as swiss_tax_id, pay_taxes as pay_swiss_taxes, bank_account as swiss_bank_account, deposit_to_account as deposit_to_swiss_account,... select swiss_address, swiss_tax_id, pay_swiss_taxes, swiss_bank_account, deposit_to_swiss_account end US_TAXPAYER rename address as us_address, tax_id as us_tax_id,... end

Chair of Software Engineering OOSC - Summer Semester Creating with a specified type  To avoid this: a1: A b1: B... create b1.make (...) a1 := b1  Simply use a1: A... create {B} a1.make (...) A BC

Chair of Software Engineering OOSC - Summer Semester Once routines  If instead of r is do... Instructions... end  you write r is once... Instructions... end  then Instructions will be executed only for the first call by any client during execution. Subsequent calls return immediately.  In the case of a function, subsequent calls return the result computed by the first call.

Chair of Software Engineering OOSC - Summer Semester Scheme for shared objects class SHARED_OBJECTS feature error_window: WINDOW is once create Result.make (...) end exit_button: BUTTON is once create Result.make (...) end... end class MY_APPLICATION_CLASS inherit SHARED_OBJECTS feature r is do error_window.put (my_error_message) end... end

Chair of Software Engineering OOSC - Summer Semester Undefining a feature deferred class B inherit A undefine f end feature... end

Chair of Software Engineering OOSC - Summer Semester Feature merging ABC D f* f+f+

Chair of Software Engineering OOSC - Summer Semester Feature merging (cont’d) class D inherit A B C feature... end

Chair of Software Engineering OOSC - Summer Semester Feature merging: with different names ABC D g* f*h+h+ g f h f

Chair of Software Engineering OOSC - Summer Semester Feature merging: with different names class D inherit A rename g as f end B C rename h as f end feature... end

Chair of Software Engineering OOSC - Summer Semester Feature merging: effective features a1: Ab1: Bc1: Cd1: D a1.gb1.fc1.hd1.f ABC D g*g* f*f*h+h+ g f h f f-f-f-f-

Chair of Software Engineering OOSC - Summer Semester Feature merging: effective features class D inherit A rename g as f undefine f end B C rename h as f undefine f end feature... end

Chair of Software Engineering OOSC - Summer Semester When is a name clash acceptable?  (Between n features of a class, all with the same name, immediate or inherited.)  They must all have compatible signatures.  If more than one is effective, they must all come from a common ancestor feature under repeated inheritance.

Chair of Software Engineering OOSC - Summer Semester Feature adaptation clauses  rename  export  undefine  redefine  select

Chair of Software Engineering OOSC - Summer Semester Export adaptation class B inherit A export {ANY} all {NONE} h {A, B, C, D} i, j, k end feature...

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