Design patterns [8] *) and frameworks are frequently represented by groups of cooperating, interdependent classes that reference each other and that have to be specialized/derived collectively in a consistent way in order to be used in actual applications. The term "framework" refers to the overall, top-level structure of entire applications while "design patterns" may also deal with groups of lower-level interdependent "generic utility classes" that may be specialized for concrete usage. Although the definition of design patterns would be given in natural language, perhaps enhanced by sketchy sample programs in a concrete programming language, it would be highly desirable to provide immediately reusable versions of design patterns in concrete programming languages like Lava.
The widespread programming languages, however, do not provide proper expressive means for implementing concrete incarnations of design patterns. Parameterized classes as the "templates" of C++ or the "generic classes" of Eiffel do not meet the requirements: They can be viewed as special macros or as type generation constructs having three serious drawbacks:
For the design of Lava we have drawn the following conclusions from this situation and from the fact that we have a package notion in Lava anyway that allows us to form groups of related classes or other declarations:
The currently valid value of a pattern parameter or "virtual type (VT)" is taken at run time from a "virtual type table (VTT)" similar to the usual "virtual function table (VFT)" of object-oriented programming systems. As usual, Lava provides for every Lava object a pointer to its associated VFT, but additionally also a pointer to an associated VTT. Like the VFT, the proper VTT is determined on object creation, roughly spoken as the "pattern context" of its implementation, and this is in turn the pattern context of the class that the latter implements.
Generally, we use the term type for a concrete class or a virtual type / pattern parameter in the sense explained above. (Both may be referenced as types of variables in Lava programs.)
A type is called a multiform type if it is either a virtual type or a class that is declared within a pattern. The structure and meaning of a multiform type may depend on the pattern context where it is used. We use "uniform" as a synonym for "non-multiform".
Virtual types may be referenced anywhere (on any nesting level) within their "owner" package or class, but also in implementations of classes belonging to that scope. (These implementations may be located even outside this scope.)
Summary: A Lava pattern is just a quite normal package or class declaration, having virtual types.
In the Lava declaration view a pattern is just a quite normal package or class declaration, having virtual types (VT). A virtual type vt has a name and a value VAL(vt). The value may be a class (having the name of the virtual type) or the name of another VT. (The term "bound" is also used in the literature for the value of a VT.)
A virtual type may also be "abstract". Then its value is "empty"; a non-empty value may be assigned when overriding the abstract VT in a derived pattern.
A VT is called "final" if its value is a class. This class cannot be referenced then as a normal class within the containing pattern; its name rather denotes the VT whose value it is. Outside the pattern, it denotes just the class.
Moreover, classes (and virtual types anyway) of a derived pattern P cannot be referenced in base patterns of P.
A VT has a name and a value. The value may be (the name of) a class or of another VT. A virtual type may also be "abstract". Then its value is "empty"; a non-empty value may be assigned when overriding the abstract VT in a derived pattern.
Generally, package and class declarations may be nested to any depth in Lava (but class declarations cannot contain nested package declarations). For packages and classes with virtual types the above-mentioned restrictions apply, however.
Specialization of patterns makes use of the same Lava override view that is also used for quite normal class derivation.
A special section of this documentation has been dedicated to the static type-safety of Lava. The relation of our approach to other notions of virtual types is discussed here. An outline of the proof of the static type-safety of Lava can be found at the same place.
See also: