Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Fitters
Fitter definition

A fitter is a specification of how to initialize when an instance is created.


Table of contents:


Format

Access control

fitter

Class name

Argument

endfitter

Default fitter

Example

Format

The format of the fitter definition is:


Access-control fitter Class-name(Argument)

...

endfitter


It is a definition that starts with access control, followed by the keyword fitter, and ends with the keyword endfitter.

The name of the fitter must be the same as the class name.

You can define fitters that combinations of arguments are different and place anywhere in the class definition.

The fitter definition will generate a scope.

Access control

It specifies the access level of the fitter using the keywords open or closed.

If you specify open, the fitter can be called from outside of the class definition.

If you specify closed, the fitter can only be used inside of the class definition.

fitter

It is a keyword that indicates that it is a fitter definition. It must be specified next to access control.

Class name

It specifies the class name after the keyword fitter.

Argument

Fitter arguments are specified next to the Class-name, it must be enclosed by parentheses.

An argument is a pair of class name and argument name.

If there are two or more arguments, separate them with commas. No comma is required when one argument. If no argument, the parentheses are empty.

Since the fitters are distinguished by the order of the argument classes, you can define fitters as many as you like if they have different argument order.

endfitter

It is a keyword that indicates the end of the fitter definition.

You can use the abbreviation "ef" instead of "endfitter". Note that "ef" is also a keyword.

Default fitter

A fitter with no arguments is called a default fitter. If there is a user-defined default fitter, it will be called.

If there is no user-defined default fitter, a default fitter is automatically generated and called.

The instance returned by the automatically generated default fitter is the same as if a variable of that class was declared.

Example

Let's define fitters in the example class.

1:

class example

2:

int x;

3:

int y;

4:

open fitter example() // Default fitter.

5:

x = 0;

6:

y = 0;

7:

endfitter

8:

open fitter example(int xx, int yy) // Fitter with two arguments.

9:

x = xx;

10:

y = yy;

11:

ef // Abbreviation.

12:

endclass

The fitter is called with a new expression.

1:

example ex = new example(10, 10);

Next
Previous
Copyright © Rice All rights reserved.