Makes a trait, a construct that changes how a class or structure behaves.
[ @Abstract ] Trait trait_name [ type_list ] [ Does parent_trait ]… [ Where generic_constraints ] … [ statements ] End [ Trait ]
- Optional modifier specifies that the trait contains only signatures of procedures, not executable statements or variables.
- Mandatory name for the trait
- Optional one or more type parameters, with a comma between each, all between brackets (
[ ]). See Type List for more information.
- Optional, you can use again and again.
- Mandatory after
Does, a different trait from which
- Optional, you can use again and again. See Where Clause (Generics) for more information.
- Optional declarative statements.
- Completes the statement.
You can also use
- You can change this part of the syntax. See @Option Directive for more information.
A trait defines a set of members that can become a part of the interface of classes and structures. If the trait does not implement a method or property, then the class or structure must implement it. A trait that supplies only an interface, and does not implement its methods or properties, is known as an abstract trait.
When you make a class or structure that uses a trait, the code supplied by the trait becomes part of your class or structure. If a trait member is not implemented, then you must implement that member in your class or structure.
You can use Trait only at module level. The declaration context can be a class, structure, module, or trait, and cannot be a procedure or block. See Declaration Contexts and Default Access Levels for more information.