Eiffel Introduction Part V (2)

zhaozj2021-02-08  324

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

转载请注明原文地址:https://www.9cbs.com/read-394.html

New Post(0)