Constraint Genericity

(Also known as Generic Constraint and Bounded Parametric Polymorphism)

The term is used in the Eiffel programming language [1,pp. 77-79], to describe the programming language feature of being able to constrain the static (compile-time) type of generics.

Consider the code for the class given below (Example and terminology adopted from [2])

public class Collection<T>
{...
      public boolean exists (T aElement);
      public void addElement (T aElement);
      public void removeElement (T aElement);
      public T getFirstElement (void);
}

In this code listing there is no inherent type information about the parameter T. In a hierarchical type system, that has a root class (ie. Object in Java) we say that the upper bound on the type of T is the aforementioned root class. Contrast this with the code given below

public interface Ordered
{...
      public boolean lessThan (Object aObj);
}

public class OrderedCollection<T implements Ordered>
      extends Collection
{...
}

Here the upper bound on T is Ordered (hence the phrase bounded parametric polymorphism). The main difference between these two approaches is the ability of the later to do static type-checking without explicit casting (ie. a element returned from a call to getFirstElement does not have to be explicitly cast from the root class).

Many languages support bounded parametric polymorphism. According to [3] the language construct exists in languages like Standard ML, O'Caml, Haskell. In [4] there is a short introduction to generic in Java.

[1]
Standard ECMA-367, Eiffel Analysis, Design and Programming Language, http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-367.pdf.
[2]
Jose H. Solorzano and Suad Alagic, Parametric polymorphism for Java: a reflective solution, ACM SIGPLAN Notices 33,10 (Oktober 1998), 216-225.
[3]
Wikipedia, Polymorphism (computer science), http://.en.wikipedia.org/wiki/Parametric_polymorphism#Parametric_polymorphism.
[4]
Sun Microsystems, Generics, http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html.
Back to the Glossary of Generative Programming Terms
Back to the course home page
Contributor: Mads Ravn
Last modification: 31/1 2006