-
Notifications
You must be signed in to change notification settings - Fork 2
Interfaces Tutorial
Interfaces are similar to inheritance in their usage and purpose. They are also used when multiple classes share a certain characteristic. However, interfaces can be used much more diversely, as their implementers don't need to share anything except the interface itself.
An interface is defined much like a class:
interface "IName" {
variable = "value";
}
function IName:method()
endAnd is added to a class as follows:
class "Name" implements "IName" {}However, unlike inheritance, multiple interfaces can be implemented by a class.
Just like inheritance, a class that implements an interface will show all the interface's variables and methods unless overridden.
Constructors can be useful for interfaces as well as classes. However, they are not handled automatically. If an interface does have a constructor, it will need to be called manually inside the class' constructor. Interface constructors should follow the same naming rules as class constructors (InterfaceName:InterfaceName()).
- Multiple, un-related classes that share code.
- Modularising a large but related portion of a class.
- Multiple, related classes (inheritance should be used instead).
- Classes that don't use most of the interface.
- Unrelated code in one interface.
- Exception
- DynamicValueException
- ExpressionException
- IncorrectConstructorException
- IncorrectParameterException
- ParserException
- ResourceLoadException
- ThreadRuntimeException