Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 7 13. October 2008.

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.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 5 6 October 2008.
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 1 Introduction to Programming Bertrand Meyer Exercise Session November 2008.
Lecture 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
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 Lecture 2: Dealing with Objects I.
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 Lecture 15: Exception handling.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 4 30 September 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 Lecture 2: Dealing with Objects I.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 2 23 September 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 3 29 September 2008.
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 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 6 7 October 2008.
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 9.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
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 Tuples and Agents Exercise Session 1 and 2 December 2008.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 14: Presentation of EiffelStudio.
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 7: References and Assignment.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
1 Advanced Material The following slides contain advanced material and are optional.
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 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 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 9.
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 Exercise Session 3.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
© 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.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
© 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 5.
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 9.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
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 4.
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 3.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
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.
You are an Acrobat When you are asked to Clap, you will be given a number. Clap your hands that many times. When you are asked to Twirl, you will be given.
© 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
The following slides contain advanced material and are optional.
Einführung in die Programmierung Introduction to Programming Prof. Dr
Session 2: Introduction to Object Oriented Programming
Einführung in die Programmierung Introduction to Programming Prof. Dr
Presentation transcript:

Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008

Chair of Software Engineering Today’s learning goals  Entities vs. objects  Object creation  Executing a system 2

Chair of Software Engineering 3 Entity vs. object (COURSE) Generating class MEMORY Fields In the class text: an entity joe: STUDENT In memory, during execution: an object (ASSISTANT) (STUDENT) (MARK) (PROFESSOR)

Chair of Software Engineering class INTRODUCTION_TO_PROGRAMMING inherit COURSE feature execute is -- Teach `joe’ programming. do -- ??? joe.solve_all_assignments end joe: STUDENT -- A first year computer science student end 4 INTRODUCTION_TO_PROGRAMMING

Chair of Software Engineering 5 Initial state of a reference In an instance of INTRODUCTION_TO_PROGRAMMING, may we assume that joe is attached to an instance of STUDENT? joe ( STUDENT ) reference ( INTRODUCTION_ TO_PROGRAMMING ) Where does this one come from? This object has been created (by someone else...) MEMORY

Chair of Software Engineering 6 By default Initially, joe is not attached to any object: its value is a void reference. joe void reference ( INTRODUCTION_ TO_PROGRAMMING )

Chair of Software Engineering 7 States of a reference During execution, a reference can be:  Attached to a certain object  Void

Chair of Software Engineering 8 To denote a void reference: use Void keyword To create a new object in memory and attach it to x: use create keyword create x To find out if x is void: use the expressions x = Void (true iff x is void) x /= Void (true iff x is attached) States of a reference

Chair of Software Engineering 9 Those mean void references! The basic mechanism of computation is feature call x. f (a, …) Since references may be void, x might be attached to no object The call is erroneous in such cases! Apply feature f To object to which x is attached Possibly with arguments

Chair of Software Engineering 10 Why do we need to create objects? Shouldn’t we assume that a declaration joe: STUDENT creates an instance of STUDENT and attaches it to joe?

Chair of Software Engineering 11 Those wonderful void references! (PERSON) spouse Married persons: (PERSON) spouse Unmarried person:

Chair of Software Engineering 12 Those wonderful void references! Last next reference is void to terminate the list. ( STOP ) next ( STOP )

Chair of Software Engineering 13 Type of a created object Every entity is declared with a certain type: stop1: SIMPLE_STOP A creation instruction create stop1 produces, at run time, an object of type SIMPLE_STOP.

Chair of Software Engineering Creation procedures 14 Instruction create x will initialize all the fields of the new object attached to x with default values What if we want some specific initialization? E.g., to make object consistent with its class invariant? class STOP … station: STATION invariant station /= Void station Use creation procedure: create stop1.set_station (station1) Incorrect!

Chair of Software Engineering 15 STOP May be used as a regular command and also as a creation procedure List zero or more creation procedures class STOP create set_station feature station: STATION -- Station which this stop represents next: SIMPLE_STOP -- Next stop on the same line set_station (s: STATION) -- Associate this stop with s. require station_exists: s /= Void ensure station_set: station = s link (s: SIMPLE_STOP) -- Make s the next stop on the line. ensure next_set: next = s invariant station_exists: station /= Void end Is established by set_station

Chair of Software Engineering 16 Object creation: summary To create an object:  If class has no create clause, use basic form, create x.  If the class has a create clause listing one or more procedures, use create x.make (…) where make is one of the creation procedures, and “(…)” stands for arguments if any.

Chair of Software Engineering 17 Executing a system Root creation procedure may:  Create new objects  Call features on them, which may create other objects  and so on... Executing a system consists of creating a root object, which is an instance of a designated class from the system, called its root class, using a designated creation procedure of that class, called its root creation procedure.

Chair of Software Engineering Some acrobatics class DIRECTOR create prepare_and_play feature acrobat1, acrobat2, acrobat3: ACROBAT friend1, friend2: ACROBAT_WITH_BUDDY author1: AUTHOR curmudgeon1: CURMUDGEON prepare_and_play is do author1.clap (4) friend1.twirl (2) curmudgeon1.clap (7) acrobat2.clap (curmudgeon1.count) acrobat3.twirl (friend2.count) friend1.buddy.clap (friend1.count) friend2.clap (2) end 18 Hands-On What’s wrong with the feature prepare_and_play? What entities are used in this class?

Chair of Software Engineering Some acrobatics 19 class DIRECTOR create prepare_and_play feature acrobat1, acrobat2, acrobat3: ACROBAT friend1, friend2: ACROBAT_WITH_BUDDY author1: AUTHOR curmudgeon1: CURMUDGEON prepare_and_play is do 1create acrobat1 2create acrobat2 3create acrobat3 4create friend1.make_with_buddy (acrobat1) 5create friend2.make_with_buddy (friend1) 6create author1 7create curmudgeon1 end Which entities are still void after execution of line 4? Which of the classes mentioned here have creation procedures? Why is this procedure necessary? Hands-On