Method Statement

Defines a method procedure for a class or library.

Syntax

Usual construction

[ modifiers ] Method method_name [ < type_list > ] [ parameter_list ] [ return_type ]
    [ Where generic_constraints ]
    [ statements ]
End [ Method ]

Abstract construction

[Abstract] Method method_name [ parameter_list ]

Name-replacement construction

[ modifiers ] Method method_name Does trait_name.old_name

Parts

modifiers
Optional, usually one, but possibly two, between square brackets:
  • Abstract – The method must be overridden by a concrete subclass. Only valid inside an Abstract Class or Trait.
  • Final – The method cannot be overridden by a subclass.
  • Override – The method overrides one inherited from a superclass or trait.
  • Shared – The method is a child of its parent construction, not an instance of some object.
You can put Final and Override together.
method_name
Necessary name.
type_list
Optional. See Type List for more information.
Not permitted in the name-replacement construction.
parameter_list
Optional in the usual construction. One or more local variables with a comma between each one. The caller gives themtheir values. See Parameter List for more information.
Not permitted in the name-replacement construction.
return_type
Optional in the usual construction.
Not permitted in the name-replacement construction.

Syntax

As type
or
In unit
type
Describe
unit
Describe
generic_constraints
Optional. See Where Clause (Generics) for more information.
statements
Optional in the usual construction.
Not permitted in the abstract and aliasing constructions.
End
Completes the statement. You can also use End Method.
Not permitted in the abstract and aliasing constructions.
trait_name
Necessary in the name-replacement construction, the name of one trait that the class applies.
old_name
Necessary in the name-replacement construction, the name of the procedure supplied by a trait.

Instructions

Do not confuse End Method with the statement Exit Method.

Method is the primary type of procedure contained in a Class, Object, Trait, or Library. Such procedures (along with Property) can be called from any place in 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 form

Abstract form

The abstract form acts like a template. It is used within an abstract class or trait. It is a guarantee that a concrete subclass or the user of a trait will provide its own implementation of the method. Therefore, it cannot contain statements of its own.

Name replacement form

You use the name replacement form when you need to change the name of a method supplied by a trait which causes a collision with a different procedure in your class.

If you must keep a method out of your class, the Function Statement has an equivalent form that can convert a public method into a private function.

Examples

See also