Modules are very similar to namespaces. They provide a way to group together properties and methods related to a particular feature.
For example, the following snippet categorises different services offered by a cafe:
package cafe;
moduleCoffeeMachine {
var cupsLeft = 10;
var isWorking = true;
funcserve()<void> {
Console.log("coffee is served!");
}
}
moduleIceCreamMachine {
var conesLeft = 10;
var isWorking = true;
funcserve()<void> {
Console.log("coffee is served!");
}
}
moduleMainimplements <EntryPoint> {
funcmain()<void> {
CoffeeMachine.serve();
IceCreamMachine.serve();
}
}
Nested Modules
Consider the following expression:
CoffeeMachine.Beans.brew();
Seems appealing doesn’t it? Well, we call this module nesting, where the Beans module is nested inside the CoffeeMachine module. This is used to further organise functionality of code within modules. To do so, declare a module like you normally would, just inside an existing module.