Dodo doc > Types > Nested Types
A type declaration can be nested in another type. In that case the nested type is linked to the enclosing type instance which creates it.
The nested type gets a default value only if it has no constructors and no attribute which value depends on the enclosing type instance. If the nested type has constructors, including a constructor with no arguments, it does not have a default value. This is because the constructor needs to know the enclosing object before it can run.
In the nested type functions, declarations of the enclosing type are declared. But the "self" variable is a reference to the current nested type instance.
Examples:
class House { struct Window(Integer) } class FoodProcessor:
def SpeedSetting = new Integer
def speed -> SpeedSetting # uses a nested type
.
A nested type can be overridden. Declarations in an overriding nested type declaration can override existing declarations in the same way as other types. Constructors are inherited and can also be overridden. Any added attribute keeps its default value when an inherited constructor is called.
Example:
struct ^Window: make ^withPaneCount(Integer) make withFinish(WindowFinish) .