Declaring classes
Instantiating classes
Declaring a class
Example
Declaring a class without a constructor
A class without a constructor can still be instantiated. In the following example the class Calculator has two fixed methods which can be accessed without the class needing to be instantiated.
Example
Declaring a non-instantiable class
A class marked fixed can not be instantiated. All functions or structs declared in it, are fixed. It may contain a constructor (but it can't be accessed without using reflection). One can declare a non-fixed class inside a fixed class and vice-versa.
Example
Declaring a class within a class
Example
Declaring a class within a function
In Hades, it is possible to declare a class in a function. This function can only be instantiated (provided it's an instantiable class) in said function but can be returned and therefore used outside the function scope.
Example
Working with inheritance
Base classes
Simple inheritance
Example
Multiple inheritance
When functions overlap each other when inheriting from multiple members, the order of the members to inherit from dictates which function is taken.
Example
Super
If you still want to make the code from the example above work, you need to call the method on Mother explicitly. The built-in super function allows you to do exactly that.
Overriding inherited members
To override a function, use the func!
keyword. This overrides functions and functions groups with function guards.
Example
Last updated