Fitter definition
A fitter is a specification of how to initialize when an instance is created.
Table of contents:
Format
The format is:
Access-control fitter Class-name(Argument)
...
endfitter
This is a definition that starts with access control, followed by the fitter keyword, and ends with the endfitter keyword.
The fitter name 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
You can specify the access level of the fitter using the open or closed keywords.
If specifies open, you can call the fitter from outside of the class definition.
If specifies closed, the fitter can only use inside of the class definition.
fitter
This is a keyword that indicates that it is a fitter definition. It must be specified next to access control.
Class name
The class name should specify after the fitter keyword. It must be the same as the class name in the class definition.
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.
You can define fitters as many as you like if they have different argument. This is because fitters are distinguished by the order of the class of arguments.
endfitter
This 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); |