A fitter is a specification of how to initialize when an instance is created.
Table of contents:
The format is:
Access-control fitter Class-name(Argument)
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.
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.
This is a keyword that indicates that it is a fitter definition. It must be specified next to access control.
The class name should specify after the fitter keyword. It must be the same as the class name in the class definition.
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.
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.
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.
Let's define fitters in the example class.
open fitter example() // Default fitter.
x = 0;
y = 0;
open fitter example(int xx, int yy) // Fitter with two arguments.
x = xx;
y = yy;
ef // Abbreviation.
The fitter is called with a new expression.
example ex = new example(10, 10);