Class Definitions

A class provides the definition for the type of an object and the variables, properties, events, and methods that the class comprises.
In addition it may declare tests to exercise the class and contracts or constraints the class must conform to to ensure continuing validity.

Classes are declared using the class keyword followed by the name of the class.
The classname must start with an uppercase letter.

The class may have any of the usual access modifiers.
The Superclass inheritance and interface conformance are indicated with the inherits and implements keywords.Attributes metadata can be specified with the has keyword.

Instance and Class Variables

Instance and Class variables are declared within the class using keyword var followed by the var name.
Like local variables they may be explicitly typed ( as <Type> ) and if not are defaulted to type dynamic.

An initial value may be specified (if not the var gets its types 'empty' value ( 0, "" or nil)
(Idiomatically its usually preferable to explicitly initialise the var and not explicitly specify the Type).

Properties

This discussion is somewhat simplified for clarity.
Please see
Properties

Properties are members that provide a flexible mechanism to read, write, or compute the values of private fields.
They are used as if they are public data members, but are actually implemented via special methods called accessors.

There are 3 keywords for defining a property:get defines a readOnly property ( Can access the properties value but cant change it). set defines a writeOnly property (Can write to the property but cant read it)pro defines a readable and writable property.

If a property accessor merely reflects a protected or private backing variable (field) you can
use a clause beginning with keyword from.

from var pro <name> from var or get <name> from var or set <name> from var
The property will get or set its value unchanged from a backing variable named
to the property name with a single underscore prepended to it.

If there is no backing variable but there is an assignment to the property or a type declaration on the property
the backing variable will be implicitly created for you.

from <backingVarName>
Otherwise the word following the from must be the name of an existing backing store variable.

Finally if an accessor needs to translate, filter or modifies in some way a backing variable or computes a value
there is a longer syntax variant where either of both the get and set accessors can be specified and a block of code
provided to store (setter) or generate (getter) the property value.

Methods

A method is a code block that contains a series of statements.
A program causes the statements to be executed by calling the method and specifying any required method arguments.

Methods are defined using the keyword def.

If not specified the returnType is void ( i.e nothing returned) and the access modifiers are public, virtual

Like variables if the name is prefixed with an _ its access modifier defaults to protected, virtual and it is directly accessible from within the class method code.
If the name is prefixed with an _ _ (double underscore) its access modifier defaults to private',virtual' and it is directly accessible from within the class method code.

Without those prefixes on the name of the methods the accessType is public, virtual and
it must be accessed from within method code by prefixing the name with either this. or just . .

Method Grammar

The initializer or constructor method of a class is a special method called init which is implicitly called when a class instance is constructed.
Its responsible for setting the contents of a class instance to an initial state.
It doesnt return any value and is not inherited (i.e baseclass initialization must be done with an explicit call to
a baseclass constructor).

If an init method is not specified the compiler runtime generates a noArg constructor that does nothing.
Because this method is 'special' it is declared using cue rather than def. See cues?

Constructor chaining must be done explicitly to another constructor in the same class (usually with a different number or Type of args)
or to a Superclass constructor (using base.init) - this call must be the first executable line in the init method.

Method Parameter List

A parameter list is a comma separated list of name (and optionally type and parameter description modifier) specifications

<paramName> [as [<paramDesc>] <Type>] [, ...]

<paramDesc> is optional and may be vari and/or a parameter direction indicator out or inout ( default if unspecified is in)

vari indicates the parameter name is a placeholder for a variable length arglist. Within the method this may be unpacked/accessed as a list.

in (implicit) Args are only passed into the method. Any changes made to the argument inside the method are not visible outside the method (pass-by-value)

out the arg is returned from the method

inout argument is both passed into the method and (any possibly changed) value is also returned from the method (pass-by-reference)