Classes and Objects
A class
is a type definition intended to be used for instances or objects. It contains a basic definitional type for its state and a number of methods
Syntactically, a class
requires the following elements:
class
keywordType name, beginning with a capital letter
Like a function, a method defines a mapping from an input value to an output value. However, it does not begin with a func
keyword.
Since a method only occurs within a class
context and is delimited by ;
“mic”, there is no syntactic ambiguity in defining them.
Syntactically, a method requires the following elements:
Method name (all lower case)
In parentheses, one or more arguments (the state)
In braces, code block of body
A number of methods
While a terminating ;
“mic” is not required, a class
is very frequently introduced using a compose
statement which requires a ;
“mic” to end its context definition.
Methods in class
definitions are similar to functions, but must occur inside a class
code block and do not have a prefatory func
keyw
Last updated