Method Statement

Makes a method procedure for a class or library.

Syntax

Usual construct

[ modifiers ] _
Method method_name [ type_list ] [ parameter_list ] [ return_type ]
    [ Where generic_constraints ]…
    [ statements ]
End [ Method ]

Abstract construct

@Abstract Method method_name [ parameter_list ]

Name-change construct

[ modifiers ] _
Method method_name Does trait_name . supplied_name

Parts

modifiers
Optional, usually one, but possibly two of these:
  • @Abstract – The method has no implementation. You must implement it in a child class. See @Abstract.
  • @Const – The method can run at compile-time. This puts many limits on the method. See @Const.
  • @Deprecated – You can remove the method in a subsequent release of a library. See @Deprecated.
  • @Iterator – The method implements the iterator pattern. The procedure must have a return type. See @Iterator.
  • @MustUse – Code that calls the procedure must use the result. See @MustUse.
  • @Open – The method can have a different implementation in a child class. See @open.
  • @Override – The method is a different implementation of a method inherited from a parent class or trait. See @Override
  • @Shared – The method is a member of a container, for example, a class, and not an instance of that container. See @Shared.
method_name
Mandatory name for the method.
type_list
Optional one or more names with a comma between each, all between brackets ([ ]). See Type List for more information.
Not permitted in the name-change construct.
parameter_list
Optional in the usual construct. One or more local variables with a comma between each. The caller gives them their values. See Parameter List for more information.
Not permitted in the name-change construct.
return_type
Optional in the usual construct.
Not permitted in the name-change construct.

Return type

As type
or
In unit
type
A data type.
unit
A unit of measure.
generic_constraints
Optional. See Where Clause (Generics) for more information.
statements
Optional in the usual construct.
Not permitted in the abstract and name-change constructs.
End
Completes the statement. You can also use End Method.
You can change this part of the syntax. See @Option Directive for more information.
Not permitted in the abstract and name-change constructs.
trait_name
Mandatory in the name-change construct, the name of one trait that the class applies.
supplied_name
Mandatory in the name-change construct, the name of the procedure supplied by a trait.

Instructions

End Method is not the same as Exit Method.

Method is the most usual type of procedure contained in a Class, Object, Trait, or Library. You can call such procedures (along with Property) from all parts of a program where its container is in scope. Procedures of the types Function and Sub can only be seen by other procedures in the same container.

Usual construct

TODO

Abstract construct

The abstract construct is almost the same as a template. It is used in an abstract class or trait. It makes sure that a concrete child class or the user of a trait will supply its own implementation of the method. Thus, it cannot contain statements.

Name-change construct

You use the name-change construct when you must change the name of a method supplied by a trait which has the same name as a procedure in your class.

If you must keep a method out of your class, Function has an equivalent construct that can change a public method into a private function.

Examples

TODO

See also