11.1 General
A class defines a user-defined reference type that combines data and executable behaviour into a single declaration.
A class may declare:
- fields
- properties
- constants
- Functions
- Subs
- constructors
- nested types
A class declaration introduces a new named type.
11.2 Class Declarations
A class declaration specifies:
- the class name
- optional generic parameters
- optional modifiers
- the class body
The class body contains the declarations that define the state and behaviour of instances of the class.
11.3 Instances
An instance is an object created from a class.
Each instance contains its own copy of the instance state declared by the class.
Member Functions and Subs operate upon a particular instance unless declared otherwise.
The mechanism used to create instances is described in Section 11.7.
11.4 Members
Members define the capabilities of a class.
A class may contain:
- fields
- properties
- constants
- constructors
- Functions
- Subs
- nested declarations
Each member has its own accessibility, lifetime, and semantics.
The grammar for each member category is described in the corresponding chapter.
11.5 Visibility
Member visibility determines where a member may be referenced.
The language defines accessibility rules that govern the visibility of declarations both within and outside the declaring class.
Accessibility is enforced during compilation.
11.6 Member Invocation
Member Functions and Subs are invoked through an instance of the class unless declared as type members.
Invocation follows the same overload resolution and parameter matching rules defined for all routines.
The only distinction is that the invocation occurs within the context of a particular object.
11.7 Construction
An object is created by invoking one of the constructors defined by the class.
Construction allocates storage for the new instance and performs any initialization required by the class.
If multiple constructors are declared, overload resolution determines which constructor is invoked.
The construction process completes before the resulting object becomes available to the caller.
11.8 Object Lifetime
The lifetime of an object begins when construction completes.
The mechanism by which object storage is reclaimed is implementation-defined.
Programs shall not depend upon any particular memory management strategy unless explicitly documented by the implementation.
11.9 Generic Classes
A class may declare one or more generic type parameters.
Each specialization of a generic class represents a distinct constructed type.
Generic classes participate fully in the generic programming facilities described in Chapter 10.
11.10 Nested Classes
A class may contain additional class declarations.
Nested classes obey the normal rules governing visibility, accessibility, and generic parameter scope.
11.11 Summary
Classes define reference types that combine state and behaviour.
They provide the primary mechanism for representing complex program entities whose lifetime extends beyond a single routine invocation.
