Download presentation
Presentation is loading. Please wait.
Published byLesley Lang Modified over 9 years ago
1
© 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 http://eiffel.com
2
© Bertrand Meyer and Yishai Feldman Classes A class is an abstract data type equipped with a possibly partial implementation.
3
© Bertrand Meyer and Yishai Feldman Objects An object is an instance of a class.
4
© 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.
5
© 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.
6
© 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.
7
© Bertrand Meyer and Yishai Feldman Object Rule Every object is an instance of some class.
8
© Bertrand Meyer and Yishai Feldman Inheritance and Basic Types NUMERIC COMPARABLE DOUBLE REAL INTEGER
9
© Bertrand Meyer and Yishai Feldman Example: POINT
10
© 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
11
© 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
12
© Bertrand Meyer and Yishai Feldman POINT Impementations
13
© Bertrand Meyer and Yishai Feldman Feature Classification by Role
14
© Bertrand Meyer and Yishai Feldman Feature Classification by Implementation
15
© 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.
16
© 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
17
© 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
18
© 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
19
© 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
20
© 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.
21
© 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
22
© 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.
23
© 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)
24
© 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.
25
© 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.
26
© 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.
27
© 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
28
© 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
29
© 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
30
© 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).
31
© 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
32
© 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
33
© 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.
34
© 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.
35
© 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.
36
© 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.