Eiffel Introduction Part III

zhaozj2021-02-08  377

Eiffel Introduction

Eiffel introduction

Rensselaer, 2000

James C. McKim, JR, Rensselaer At Hartford

K] [N g of @ r k translation

3 Eiffel Categories (Class)

3.1 Category (Class)

l Each category is saved separately in a file to implement an abstract data type (Abstract Data Type).

l A category user (Clients) requires a public interface (public interface) of this category, which is called Short Form in Eiffel.

l A category common interface includes the grammar and semantics of public features, but does not include implementation details.

3.2 Category structure

Each Eiffel category has the same basic structure:

Class

Class_name

Creation

If you need, you will write a creation program for creating this category entity here.

FEATURE

All attributes (attributes; or variables) of this category

Routines ([Translation 1 / OOSC2E P89])

end

l Creation clauses contain the name of the Routines that needs to be called when creating this category entity (Instance; also known as Object, object).

l Feature clauses can have multiple. We will see this way of writing later.

l Each Feature clause contains both Attributes and Routines. It is usually a place where a large number of code is written.

3.3 Attributes (Properties)

The so-called ATTRIBUTE is a variable.

x: INTEGER

S: string

Stack: stack [string]

l Some languages ​​use the term instance variable (entity variable) to describe Attribute.

LEIFFEs in the public attributes (public attribute) for this object (Read-only).

3.4 Routines ([Translation 1 / OOSC2E P89])

Routines is:

Routine_name is

- Here is a statement of local variables

DO

...

...

end

l Routines can be both procedures (process, no return value), or Functions (function, return value).

l Of course, Routines can take parameters.

3.5 Procedures (Procedure) and Functions

Push (x: g) IS - this is a process

DO

- Let X become the top elements of the stack

end

Top: g is - This is a function

DO

- Return to the top elements to the caller of the function

end

In the function body of this function, the reserved word Result will accept a value. This value is the return value returned to the function caller.

3.6 CREATION Routines L Usually each Eiffel class contains a CREATION clause. This clause lists the name of "Features [Translation 2]" that can initialize the category object.

l When the user (Client) wants to create a category entity, these Features must be called.

[Translation 2: Features, the Attributes or Routines listed in the Feature clause of this category

If make is Creeion Creation Routine, Class C's User (Client) must create an entity for variable C: c using the following syntax:

!! c.make

or

Create C.Make

!! (CREATE) Syntax is only used when creating a new object.

The above code means:

1. Assign space for the entity (object) of the type C, and make C becomes a reference to the object (reference; or Pointer, pointer).

2. Give each Attribute (attribute) in the object to the default value (various default values: integer, 0; real, 0.0; characters, null; boolean, false; other type Don't, Void).

l It can be noted that these defaults are part of language definitions that do not depend on a specific compiler.

l When the object referred to in C is created, Class C's Make Routine is running.

s Note that if make is a public feature (public feature), the user can call it at any time, not just when the object is created. On the other hand, if Make is Private, it can only be called during the creation of the object.

3.7 Feature clause

Feature clauses are divided into two cases:

l Keyword Feature itself is equivalent to Feature {any} on syntactics. The Features defined in such clauses can be accessed by any other object. The definition of Features is a public feature content or an exported featureS.

l The Features defined in the words that are assumed in feature {none} cannot be accessed by other objects. This definition of Features is a private feature of category.

3.8 Categories in Eiffel (Continued)

Eiffel is a language that is not sensitive to case, but in order to improve readability, it should follow some agreements:

1. The name of the category is all written.

2. Keywords and user-defined names all use lowercase.

3. Reserved words (such as Result, True, False, Void, etc.) are used herein.

l Use the underline to divide the Feature name or category name (such as a category Linked_List) composed of multiple words.

l This simple consistency will be easily implemented, mainly to help read code. (to be continued)

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

New Post(0)