Classes
To create own object in object-oriented programming language (including the Cind language)
there must be defined a schema of object behaviour, named class
(the name comes from the general assumption, that there will be many objects of one class).
In Cind language, a class is a definition of behaviour of own-created objects,
that contains definition of each object's context, catched methods, inheritance connection
and other attributes.
Objects of defined classes are used as a data in Cind language, next to the other values
(see Data types) and therefore, they can be stored in a variables as values
(see Variables).
There are three kinds of classes: basic class (described here),
monitor class (see Monitor class)
and selector class (see Selector class).
Typical class definition looks like:
Instruction
For example:
will create one object of the above class
An empty vector
For every created new object of defined class,
a separate set of variables defined in the class will be reserved in memory.
This set of variables and other own attributes is named object's context (see below).
For more about instruction
A class can also refer to the other class, in so-called inheritance relation,
in the sense, that it can be some kind of a cover of the other class.
For inheritance relation see Class inheritance.
Type of object
Type of object of class is the class itself.
For example:
is a declaration of variable
what means, that it will store objects of class
And this statement:
declares variable
For more about types see Data types.
Global and local classes
Classes can be divided into global and local.
Global class is declared out of any context, has name like
Local class is declared in some context (inside some code), has name without dots,
and objects of that class can be created only from the code, where class declaration is visible.
For more about space included in the class name see Spaces.
Context
Object's context is a set of variables, functions, conditions and other attributes defined in the class,
which are created separately for each object of the class. This variables can be accessed
only from the class' code.
Example:
In above, variables
An object's context is created for each object separately,
which distinguishes it from the static context, which is shared by all objects of given class.
For information about static context see Static code.
Notice, that it is unable to access object's context from the outside of the class code.
To be able from the outside to set some values assigned to the object use properties (see Object's properties).
Methods
A method of a class is a kind of function defined inside the class and executed in the object's context,
but called from the outside.
Method is identified by name.
Declaration of method starts with dot character
For example:
is a definition of method named
For syntax of parameters of method see Parameters of function.
To call a method combine an object, method name after dot, and call parameters.
For example:
it creates object
A method of given object can be handled like a function, and stored in variable of
It is allowed to use a number of names in one method definition,
which will be equivalent to defining a set of methods with the same code.
The metod names must be separated by a vertical line character
For example:
it defines a method with three names:
General message catcher
General message catcher defined in the class allows to catch any message
which has no corresponding catch method defined in the class.
Example:
Syntax of general message catcher at the beginning contains a dot character
The variable in the brackets will contain a string name of catched message.
In above example, calling methods
When class doesn't have a general message catcher defined,
then not catched message will be passed down in inheritance chain
(see Sending messages to objects and Class inheritance).
Constructor
Constructor of object is a piece of code, executed only once, when object is created.
The main role of constructor is to initialize object's context (assign values to variables, and so on)
before the object will be used.
Constructor's section starts with keyword
The result returned by constructor is omitted.
Example of constructor declaration inside class:
Parameters passed to object's constructor are taken from the instuction
For example, instruction:
creates object of class
This instruction suspends until the object's constructor is done.
For syntax of parameters see Parameters of function.
In fact, object's constructor consists of all code written in class declaration,
including variable initialization, code sections and static sections,
and will be executed in order of apperance in the class declaration,
but the parameters will be passed only to the
For example for class:
constructor of object of this class will execute code in sequence:
Destructor
Destructor of object is a piece of code executed when object is no longer used
and is going to be removed from the memory.
It is executed by program's execution software while is making memory cleanup (see Memory management).
Destructors are executed concurrently to the main program.
Destructor's section starts with keyword
The result returned by destructor is omitted.
Example of destructor declaration inside class:
It is not determined when destructor will be executed, or even if it will ever be
(in example, when unused object is still stored in some forgotten variable,
then execution software thinks that it is still used),
so programs algorithms should not rely on destructors.
Operators
An arithmetic instruction is an expression consists of the sign of the operator and the arguments.
For example:
is an arithmetic instruction, where
An operator may also be applied to the objects of classes.
It that case, it must be defined inside the class of the object of its first argument.
In above example, in the class of the object
An operator definition in the class consists of the colon character written twice
is a class containing definition of two operators
And therefore, it is possible to make the operations
making those arithmetic instructions will execute an appropriate operators code defined in the class.
Unlike in method definition, it is not allowed to define several operators in one definition,
because character of the separator
It is allowed to define only known operators, that is:
but not the new ones, for example:
Notice also, that minus operator is distinguished from unary minus operator,
by the number of parameters in its definition.
Type conversion
A conversion of the object to the different data type may be defined in its class,
just like the operator, after characters
When object of a class needs to be converted to given type,
the executing software will execute an appropriate type conversion method.
The value returned from the code will not be treated as a conversion result,
but will be converted again, until it finally reach expected data type.
Example of type conversion metods defined in the class:
For more information about converting objects see Type conversion.
Properties
Properties of object can be initially set in the class declaration,
and they will be assigned to the object while executing the object constructor.
Syntax of the property declaration in the class is the property name
and the value after colon character
Example of properties declated in the class:
For more about properties see Object's properties.