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

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.
Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.
Chair of Software Engineering The alias calculus Bertrand Meyer ITMO Software Engineering Seminar June 2011.
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.
Object-Oriented Software Construction Bertrand Meyer 2nd ed., Prentice Hall, 1997.
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.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
UML – Class Diagrams.
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 Object-Oriented Software Construction Bertrand Meyer.
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.
-5- Exception handling What is an exception? “An abnormal event” Not a very precise definition Informally: something that you don’t want to happen.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
1 Advanced Material The following slides contain advanced material and are optional.
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.
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 Lecture 4: The Interface of a Class.
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 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 ATOT - Lecture 23, 23 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 7: References and Assignment.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
Chapter 13: Object-Oriented Programming
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
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 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Chair of Software Engineering ATOT - Lecture 22, 18 June Advanced Topics in Object Technology Bertrand Meyer.
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
Ranga Rodrigo. Class is central to object oriented programming.
Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features.
10 Conversion. Let’s start with conformance Conformance determines when a type may be used in lieu of another. Conformance relies on inheritance. The.
© 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.
© 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.
Ceg860 (Prasad)L7Class1 Classes. ceg860 (Prasad)L7Class2 Class :: Instance (Object) Static structure vs Run-time structure (Analogy -- a statue :: Lincoln.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
1 Programming for Engineers in Python Autumn Lecture 6: More Object Oriented Programming.
© 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.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Lecture 9 Symbol Table and Attributed Grammars
Design by Contract Jim Fawcett CSE784 – Software Studio
Introduction to the C Language
Chapter 3: Using Methods, Classes, and Objects
Appendix A Object-Oriented Analysis and Design
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Appendix A Object-Oriented Analysis and Design
Appendix A Object-Oriented Analysis and Design
Presentation transcript:

© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice Hall). Included here by permission of ISE, for the benefit of IDC students. Other uses, duplication or distribution require permission from ISE. For more material see

© Bertrand Meyer and Yishai Feldman Classes A class is an abstract data type equipped with a possibly partial implementation.

© Bertrand Meyer and Yishai Feldman Objects An object is an instance of a class.

© Bertrand Meyer and Yishai Feldman Type-Token Confusion Among the countries in Europe we may identify the Italian. The Italian has a mountain chain running through him North-South and he likes good cooking, often using olive oil. His climate is of the Mediterranean type, and he speaks a beautifully musical language.

© Bertrand Meyer and Yishai Feldman Coad and Yourdon: Object-Oriented Analysis, 1990 [W]e might identify a “User” Object in a problem space where the system does not need to keep any information about the user. In this case, the system does not need the usual identification number, name, access privilege, and the like. However, the system does need to monitor the user, responding to requests and providing timely information. And so, because of required Services on behalf of the real world thing (in this case, User), we need to add a corresponding Object to the model of the problem space.

© Bertrand Meyer and Yishai Feldman Coad and Yourdon: Object-Oriented Analysis, 1990 [W]e might identify a “User” Object in a problem space where the system does not need to keep any information about the user. In this case, the system does not need the usual identification number, name, access privilege, and the like. However, the system does need to monitor the user, responding to requests and providing timely information. And so, because of required Services on behalf of the real world thing (in this case, User), we need to add a corresponding Object to the model of the problem space.

© Bertrand Meyer and Yishai Feldman Object Rule Every object is an instance of some class.

© Bertrand Meyer and Yishai Feldman Inheritance and Basic Types NUMERIC COMPARABLE DOUBLE REAL INTEGER

© Bertrand Meyer and Yishai Feldman Example: POINT

© Bertrand Meyer and Yishai Feldman Point ADT (1) u Type v POINT u Functions v x, y, rho, theta : POINT  REAL v distance : POINT  POINT  REAL v translate: POINT  REAL  REAL  POINT v rotate : POINT  REAL  POINT v scale : POINT  REAL  POINT

© Bertrand Meyer and Yishai Feldman Point ADT (2) u Axioms (partial) v x (translate (p, a, b)) = x (p) + a v y (translate (p, a, b)) = y (p) + b v rho (rotate (p, alpha)) = rho (p) v theta (rotate (p, alpha)) = theta (p) + alpha v x (scale (p, a)) = x (p) a v y (scale (p, a)) = y (p) a

© Bertrand Meyer and Yishai Feldman POINT Impementations

© Bertrand Meyer and Yishai Feldman Feature Classification by Role

© Bertrand Meyer and Yishai Feldman Feature Classification by Implementation

© Bertrand Meyer and Yishai Feldman Uniform Access The value of the x feature of p is always given by the expression p.x whether its effect is to access a field or to execute a routine.

© Bertrand Meyer and Yishai Feldman POINT Class (1) indexing description: "Two-dimensional points" class POINT inherit ARITHMETIC feature x, y: REAL-- Abscissa and ordinate rho: REAL is-- Distance to origin (0, 0) do Result := sqrt (x ^ 2 + y ^ 2) end theta: REAL is-- Angle to horizontal axis do  end

© Bertrand Meyer and Yishai Feldman POINT Class (2) distance (p: POINT): REAL is-- Distance to p do Result := sqrt ((x – p.x) ^ 2 + (y – p.y) ^ 2) end translate (a, b: REAL) is -- Move by a horizontally, b vertically. do x := x + a y := y + b end

© Bertrand Meyer and Yishai Feldman POINT Class (3) scale (factor: REAL) is-- Scale by factor. do x := factor * x y := factor * y end rotate (angle: REAL) is -- Rotate by angle. do  end end

© Bertrand Meyer and Yishai Feldman Current distance (p: POINT): REAL is -- Distance to p do if p /= Current then Result := sqrt ((x – p.x) ^ 2 + (y – p.y) ^ 2) end

© Bertrand Meyer and Yishai Feldman Client, Supplier Let S be a class. A class C that contains a declaration of the form a: S is said to be a client of S. S is then said to be a supplier of C.

© Bertrand Meyer and Yishai Feldman Client of POINT class GRAPHICS feature p1: POINT  some_routine is -- Perform some actions with p1. do  Create an instance of POINT and attach it to p1  p1. translate (4.0, –1.5)  end

© Bertrand Meyer and Yishai Feldman Feature Call Effect of calling a feature f on a target x Apply feature f to the object attached to x, after having initialized each formal argument of f (if any) to the value of the corresponding actual argument.

© Bertrand Meyer and Yishai Feldman Single Target Principle Every operation of object-oriented computation is relative to a certain object, the current instance at the time of the operation’s execution.  p1.distance(p2)  distance(p1, p2)

© Bertrand Meyer and Yishai Feldman The Module-Type Identification The facilities provided by class POINT, viewed as a module, are precisely the operations available on instances of class POINT, viewed as a type.

© Bertrand Meyer and Yishai Feldman The Role of Current Current is the target of the current call. In the instruction x := x + a in the call p1. translate (4.0, –1.5) the name x refers to p1. x.

© Bertrand Meyer and Yishai Feldman Feature Call Principle F1 No software element ever gets executed except as part of a routine call. F2 Every call has a target.

© Bertrand Meyer and Yishai Feldman Unqualified Calls transform (a, b, factor: REAL) is -- Move by a horizontally, b vertically, -- then scale by factor. do translate (a, b)-- Current.translate (a, b) scale ( factor)-- Current.scale ( factor) end

© Bertrand Meyer and Yishai Feldman Operator Features (1) class REAL feature plus (other: REAL): REAL is do  end minus (other: REAL) REAL is do  end negated: REAL is do  end less_than (other: REAL): BOOLEAN is do  end  Other features  end

© Bertrand Meyer and Yishai Feldman Operator Features (2) class REAL feature infix "+" (other: REAL): REAL is do  end infix "–" (other: REAL) REAL is do  end prefix "–": REAL is do  end infix "<" (other: REAL): BOOLEAN is do  end  Other features  end

© Bertrand Meyer and Yishai Feldman Selective Exports and Information Hiding class S feature f  g  feature {A, B} h … feature { } i … feature {NONE} j … end u f and g are available to all clients. u h is available only to A, B, and their descendants. u i and j can only be used in unqualified calls: i (…) (only in the text of S).

© Bertrand Meyer and Yishai Feldman Exporting to Yourself (1) indexing note: "Invalid as it stands" class S6 feature x: S6 my_routine is do  print (x. secret)  end feature {NONE} secret: INTEGER end -- class S6

© Bertrand Meyer and Yishai Feldman Exporting to Yourself (2) indexing note: "OK now" class S6 feature x: S6 my_routine is do  print (x. secret)  end feature {S6} secret: INTEGER end -- class S6

© Bertrand Meyer and Yishai Feldman Feature Call Principle (recap) F1 No software element ever gets executed except as part of a routine call. F2 Every call has a target.

© Bertrand Meyer and Yishai Feldman Finding the Target: Unqualified Calls In an unqualified call f (a, b, …) appearing in a routine r, the target of the call is the target of the call to r.

© Bertrand Meyer and Yishai Feldman Finding the Target: Qualified Calls In a qualified call x. f (a, b, …) appearing in a routine r called with a target OBJ: v If x is an attribute, the target is the value of the x field of OBJ. v If x is a function, the target is the result of the execution of the (unqualified) call x. v If x is a local entity of r (variable or parameter), the target is the value of that entity.

© Bertrand Meyer and Yishai Feldman System Execution Execution of an object-oriented software system consists of the following two steps: Create a certain object, called the root object for the execution. Apply a certain procedure, called a creation procedure, to that object.