YAFL supports parameterized classes, which allow the creation of generic and highly typed data structures:
DEFINITION MODULE Stack;
CLASS Stack(Element);
REDEFINE METHOD CREATE;
METHOD Push(El: Element);
METHOD Pop: Element;
METHOD Top: Element;
METHOD Drop;
METHOD Dup;
METHOD Swap;
METHOD Depth: INTEGER;
END Stack;
END Stack;
When creating a new instance of such a class, an actual class must be provided for each formal class. For instance, given the Stack declaration above, one must indicate the type of the elements which are contained by a Stack instance:
VAR RectStack: Stack(Rectangle);
YAFL limits the usage of parameterized classes by requiring the actual parameters to be classes, as opposed to a predefined type such as integer, boolean or real. Such a design decision simplifies implementation significantly and guarantees excellent performance.
If one wishes to use predefined types as actual parameter to a parameterized class, YAFL's standard library includes an AbstractClasses module which declares classes which behave as syntactic sugar around predefined types.
A class marked as ONCE denotes a single instance, created automatically at initialization time. ONCE classes can be used to describe unique resources such as the standard input and output streams, a semaphore, or as recipiendary for conventional function libraries:
DEFINITION MODULE Trig;
ONCE CLASS Trig;
METHOD Sin(r: REAL): REAL;
METHOD Cos(r: REAL): REAL;
END Trig; -- End of class
END Trig; -- End of module