enum

An enum is set of predefined constants that are associated with the given name.

enum Direction {
    North South East West
}

Enum Constants with labels

Enum constants can optionally have a text ‘lexical’ value associated with it. This is often used as a descriptive name for the constant.

Labels are separate from documentation (constants have have documentation in addition to labels), and are considered part of the constant definition.

enum G7Currency {
   CAD("Canadian Dollar")
   EUR("EUR")
   JPY("Japanese Yen")
   GBP("British Pound")
   USD("American Dollar")
}

Combining Enums

ALFA allows enums to be combined to create another using includes. An enum can includes another enum to include the other’s constants. This is demonstrated below.

enum CategoryA {
   A1 A2 A3
}

enum CategoryB {
   B1 B3 B3
}

enum CategoryC {
   C1 C2 C3
}

enum AllCategories includes CategoryA, CategoryB, CategoryC { }

There is no implied relationship between AllCategories and its includes. It will simply contain all constants from its included Categories.

This includes feature is supported in enums to avoid duplication of constants between related enums.