Dodo doc > Types > Declaration
The simplest way to declare a type is with an initialisation value. In this form, the declaration starts with "def" followed by the type name, then "=" and the initialisation value. The expression after "=" is assigned to the new type and should evaluate to a type.
Examples:
def SimpleStr = String
def ItemType = Object
Note: A type can be publicly declared with an initialisation value but have a different implementation in the private section. In that case the private declaration should conform to the type of the initialisation value.
Rationale: this syntax is consistent with the way a variable is declared which helps keeping things simple. The provision that the type can be implemented independently from the public initialisation value allows to reuse just the interface of a type.
The first element of the declaration is the name of a variable
to use as prototype.
This prototype is used as base for all instances of the type via the
default value.
The new type inherits attributes and functions from the prototype type.
The second element of the declaration is a valid type name for the type.
The type name can be followed by a list of features which apply to the type, each preceded with "is". Type features are declared separately (see the section on features).
Finally the declaration can end with a declaration block which is the body of the type. Attributes and constructors should be declared in this block. It can also contain any other kind of declaration and definition.
Constructors are special functions declared with "make" instead of "def" and without a return type.
Examples:
class House is Drawable, is Colourful
{
Colour wallColour
Integer windowCount
make withWallAndWindows(Colour?, Integer?)
}
apple ShinyApple:
def shine() = "ziing!".
If the prototype is replaced with "def" then the default prototype is used, which is the same as "struct".
Note: The prototype declared publicly can differ from the prototype in the private section, as long as the private prototype is compatible with the public one. Added attributes in the private prototype become private attributes of the type.
Rationale: the return type of a constructor is always the enclosing type so there is no need to declare it.
When the prototype is struct or
class, the declaration with prototype has similar syntax to other languages.
The use of a prototype which can be
private allows types to reuse an existing implementation without
necessarily exposing the associated interface.