Pattern samples

Lava patterns provide a modern alternative to C++ "templates" and Eiffel "generic types".

Lava patterns are classes or packages with type parameters ("virtual types", VTs) whose values may be concrete classes or other VTs. These parameter types may be overridden by more derived types in a derived pattern.

Since several years there is a continuing discussion about "reusable design patterns", which describe solutions to frequently recurring software structuring problems in general terms and more or less independent of concrete programming languages. In spite of their language independence it is highly desirable to provide appropriate means for constructing individual design patterns and entire pattern libraries and "pattern languages" in concrete programming languages.

Design patterns are frequently described by families of classes that reference each other: Member variables or function parameters occurring in one class may be of a type that is specified by another class belonging to this same family. "Applying" such a design pattern will typically mean that some or all of its classes have to be specialized: You would like to replace them "collectively" by more derived classes, and this replacement should be applied also at the places where they are referenced in the original pattern as member or function parameter types. This "covariant specialization" of virtual types frees us, at the same time, from the necessity to use "type casts", as in C++ or Java, in order to make use of our knowledge that in the specialized context the run time type of many objects is actually the specialized rather than the original base type. (So type casts can be justified only on the basis of a precise understanding of the dynamic behavior of programs and can be made safe only by run time type checks, as a consequence).


Our Basic virtual type samples just demonstrate this primary purpose of patterns with virtual types.

Virtual base types provide a new kind of abstraction that enables us to specify and implement extension classes (in a generic way, "once for all") without knowing the precise concrete type(s) of the base class(es). Typical application: The well-known "decorator" design pattern. They can also be viewed as a special case of mix-in's, cf.,,, (in German).

Substitutable types enable us to deal in a (somewhat restricted but) uniform and type-safe way with objects that are incompatible in the narrow, traditional sense of class derivation with the static type T of the containing variable but whose type is derived from T in the context of some pattern derivation.