Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.

Slides:



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

© 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 Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Exercise Session 1: Eiffel Introduction.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
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 Exercise Session 6.
Design by Contract ™. 2 Design by Contract A discipline of analysis, design, implementation, management.
Chair of Software Engineering ATOT - Lecture 10, 5 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 2: Dealing with Objects I.
Chair of Software Engineering OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 8: More on inheritance.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 12: More on references and.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 4: Objects.
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 2: Dealing with Objects I.
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 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 3.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 12: Design by Contract™
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 4: The Interface of a Class.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 18: Undo/Redo.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 12: More on references and.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
Chair of Software Engineering ATOT - Lecture 11, 7 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 7: References and Assignment.
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 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 9.
Chair of Software Engineering ATOT - Lecture 5, 14 April Advanced Topics in Object Technology Bertrand Meyer.
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 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 11.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Ranga Rodrigo. Class is central to object oriented programming.
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.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Chair of Software Engineering Complement to lecture 11 : Levenshtein.
© 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 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
© 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
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
Einführung in die Programmierung Introduction to Programming Prof. Dr
Presentation transcript:

Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction

2 Topics for today Abstraction, especially functional abstraction The notion of routine The final word on features: all feature categories The Uniform Access principle Abstraction and client privileges Information hiding

3 Routine: algorithm abstraction To abstract is to capture the essence behind the details and the specifics Implies giving a name to the result In programming:  Data abstraction: class  Algorithm (operational) abstraction: routine

4 A routine is one of the two kinds of feature the other is attribute We have encountered lots of routines already, without the name.

5 A routine r (arg : TYPE ;...) is -- Header comment require Precondition (boolean expression) do Body (instructions) ensure Postcondition (boolean expression) end

6 create_fancy_line is -- Create line and fill -- stations. do -- To be completed -- BM, 26 Oct 08 end Uses of routines Bottom-up: capture existing algorithm, possibly for reuse Top-down: placeholder routines — attractive alternative to pseudocode. build_a_line is -- Build imaginary line. do Paris.display Metro. highlight create_fancy_line end

7 Procedure: doesn’t return a result  Yields a command  Calls are instructions Function: returns a result f (arg : TYPE;...): RESULT_TYPE is... (The rest as before)...  Yields a query  Calls are expressions Two kinds of routine

8 Features: the full story A class is characterized by its features Each feature is an operation on the corresponding objects: query or command Features are grouped into categories for readability Class clauses:  Indexing  Inheritance  Creation  Feature (any number)  Invariant Anatomy of a class: Demo

9 Feature Feature Features: the full story Command Query Feature Function No result Memory Computation Client view (specification) Internal view (implementation) Returns result Attribute Procedure Memory Computation Routine Feature

10 It doesn‘t matter to the client whether you look up or compute Uniform access principle A call such as your_account. balance could use an attribute or a function

11 Uniform Access: an example balance = list_of_deposits.total – list_of_withdrawals.total list_of_deposits list_of_withdrawals balance list_of_deposits list_of_withdrawals (A2) (A1)

12 Features should be accessible to clients the same way whether implemented by storage or by computation Uniform Access Principle Expressed more technically:

13 set_y set set_x An object has an interface x y

14 count first An object has an implementation x y set_y set set_x

15 Information hiding x y set_y set set_x

16 class METRO_STATION feature x, y: REAL -- Coordinates of metro station size: REAL -- Size of bounding square upper_left: POSITION -- Upper-left position of bounding square adjust_positions is -- Set positions of bounding square do upper_left. set (x – size/2, y + size/2)... end What clients may do

17 class METRO_STATION feature x, x, y: REAL -- Coordinates of metro station size: REAL -- Size of bounding square upper_left: POSITION -- Upper-left position of bounding square-- Upperposition of bounding square adjust_positions is ---- Set positions of bounding square do upper_left. x := 3... end What clients may not do NOT PERMITTED!

18 Use procedures: upper_left. set (3, upper_left. y ) upper_left. set_x (3 ) upper_left. move (3, h)

19 Possible client privileges Secret Read, restricted write Full write Read-only The attribute may be: If class A has an attribute att : SOME_TYPE, what may a client class C with a : A do with ? aatt Example: modify x with move in POINT Modify through “set_...” procedure CA a : A att

20 Possible client privileges Secret Read, restricted write Full write Read-only The attribute may be: If class A has an attribute att : SOME_TYPE, what may a client class C with a : A do with ? aatt a invalid aatt permitted in C (for access) asome_procedure Modify through aset_att (v) Modify through CA a : A att

21 Abstraction and client privileges Read access if attribute is exported  a.att is an expression.  An assignment a.att := v would be syntactically illegal! (It would assign to an expression, like x + y := v.) If class A has an attribute att : SOME_TYPE, what may a client class C with a : A do with ? aatt CA a: A att

22 Applying abstraction principles Beyond read access: full or restricted write, through exported procedures. Full write privileges: set_attribute procedure, e.g. set_temperature (u : REAL) is -- Set temperature value to u. do temperature := u ensure temperature_set: temperature = u end Client will use e.g. x. set_temperature (21.5).

23 Other uses of a setter procedure set_temperature (u : REAL) is -- Set temperature value to u. require not_under_minimum: u >= -273 not_above_maximum: u <= 2000 do temperature := u update_database ensure temperature_set: temperature = u end

24 Make it possible to call a setter procedure temperature: REAL assign set_temperature Then the syntax x. temperature := 21.5 is accepted as a shorthand for x. set_temperature (21.5) Retains contracts etc. Having it both ways

25 Status of calls in a client with a1: A: Information hiding class A feature f... g... feature {NONE} h, i... feature {B, C} j, k, l... feature {A, B, C} m, n… end  a 1. f, a1. g: valid in any client  a1. h: invalid everywhere (including in A’s own text!)  a1. j: valid only in B, C and their descendants (not valid in A!)  a1. m: valid in B, C and their descendants, as well as in A and its descendants

26 An example of selective export LINKABLE exports its features to LINKED_LIST  Does not export them to the rest of the world  Clients of LINKED_LIST don’t need to know about LINKABLE cells. Haldenegg item right Central item right Haupt- bahnhof item right first_element active count3

27 class LINKABLE [G] feature {LINKED_LIST } put_right (...) is do... end right: G is do... end... end These features are selectively exported to LINKED_LIST and its descendants (and no other classes) Exporting selectively

28 Information hiding Information hiding only applies to use by clients, using dot notation or infix notation, as with a1. f (Qualified calls). Unqualified calls (within class) not subject to information hiding: class A feature {NONE } h is... do... end feature f is do...; h ;... end end

29 What we have seen The full categorization of features Routines, procedures, functions Uniform access Information hiding Selective exports Setters and getters Eiffel: assigner commands