Eiffel Introduction
Eiffel introduction
Rensselaer, 2000
James C. McKim, JR, Rensselaer At Hartford
K] [N g of @ r k translation
5 miscellaneous topics
5.1 Simple type in Eiffel
l Eiffel Includes Character, Boolean, INTEGER, REAL, and DOUBLE.
l The assignment of the simple object and equivalence checking is the same as usual, that is, the result of A: = B is a value to A, and A = B is represented by A and B. The value is true when the value is equal.
l Check the inequality, use A / = B
l Simplified objects don't need to be explicitly created.
l In short, simple type is Value Semantics.
5.2 Class Types
l Other types other than simple types are implemented via References (reference; also known as Pointers, pointers). Such objects need to be explicitly created.
l If b = void is true, then b does not refer to any reference object. If b / = void is true, then b refers to an object that has been created.
L thus, A: = B makes A, B refer to the same object (ie, a reference to the same object). In this case, the result of A = B is true.
Like, we use A / = B to check inequality.
There is also some ways (copy, is_equal) to enable the domain (field) of a reference object to another object, and can check if the two objects contain the same value.
l In short, Class Types uses the reference semantics.
5.3 General Categories
l Each category is inherited from category any, and category Any is inheriting from category.
l void This feature is in the beloved, so each category can be used.
The other important feature of the Larges General is IO. IO is declared as an STD_FILES type, providing convenient access to the input / output program (Routines).
l For example, IO.Readint reads an integer from standard input. The result of the read is placed in o.lastint. (It can be noted that Feature, which can be changed, and Feature that only inquires only the inquiry (ie, the state cannot be changed) is separated.)
5.4 variables and objects
l To let the variable B refer to an object, there are two ways:
1. Explicitly create B objects: !! B.make 2. assign the value with the object already created: !! a.make; b: = a
l Similarly, there are two ways to make B disengage (DETACH) to an object:
1. Explicit Detachment: B: = Void2. Assign the VOID reference to B: A: = void; b: = a
5.5 constant
Use the following grammatical form to declare constant:
Constant_name: class_name is value
such as:
PI: Double IS 3.14159
Base: Integer IS 10
Hello: String is "Hello"
5.6 Object creation process without Make Routine
l Simple categories don't require a specific creative routine, it is also common.
l For example, a category that is only used to provide standard mathematical constants and functions does not require specific initialization.
L Of course, we can always provide an empty Make Routine for the category, which is not required in Eiffel. We can completely ignore the CREATION clause.
Class Basic_Math
- No Creation CLAUSE
FEATURE
PI: Real IS 3.14159
Euler: Real is 2.71828
SIN (X: REAL): Real IS
....
end
Users of this category may create a Basic_Math entity by declaring a variable, such as
BM: Basic_Math
Then execute the command
!! BM
This command allows the system to assign space for a Basic_Math type object and returns a pointer to the object to a variable BM.
In this case, you don't need to perform Make at all.
5.7 Self-reference
l Each object-oriented language provides an object to reference its own way.
l In Eiffel, use current to refer to the current object. The most frequent usage of Current is to provide another object to a reference to the previous object.
Class Some_window_class
Sub: another_window_class
...
!! Sub.make (current)
...
end
Class Another_Window_class
Parent: some_window_class
...
Make (p: some_window_class) IS
DO
Parent: = P
end
(Full text)
[Translation Reference]:
[OOSC2E] Bertrand Meyer, Object-Oriented Software Construction 2nd Edtion. 1997