Dodo doc > Types > Use as Prototype


Use as prototype

Create a new type

A type can be used as prototype, or model, for a new type. The new type inherits the declarations of its prototype and can define new ones. By default the new type also inherits the default value of its parent type as prototype for all of its instances.

Example:

def ExHouse = new House
{
Colour roofColour
ExHouse(Colour?, Colour?, Integer?)
}

Note: If the name of the type is not known, use underscore "_" as name for the constructor.

Rationale: dodo uses a type as prototype for type inheritance since using a prototype to define a new variable is a form of inheritance. This simplifies the language by reducing the number of concepts.

Overriding

A declaration in the parent type can be overridden in the new type by giving it a new definition or a new type signature. To indicate that a declaration is overridden, the name of the variable or type should be prefixed with "^". If a variable or function uses the extended syntax the "^" sign should appear before the first single quote.

An overriding attribute declaration should have a type compatible with the parent, and the parent type should be compatible in return. This usually means the types are identical.

An overriding function declaration should return a type compatible with the parent return type. The parent parameters type should be compatible with an overriding function parameters type. If they are references the overriding function parameters type should also be compatible with the parent parameters type, which usually means they are identical.

Examples:

def ^name = "Rita"
World3 ^worldDomination(Robots, Satellite, Crank)
Rationale: Unless something changes between the parent type and the new type it cannot be considered overriding. Overriding is explicit so that the intention of the programmer is clear, which reduces program bugs. The compatibility rules on overriding a type signature prevent type errors.

^ 4.2. Declaration

v 4.4. Nested Types