Implementing Traits In Java
Date: 2005 03 31
Room: CGN room C004
Title: Implementing Traits in Java
The talk will be about my thesis project.
In Object Oriented programming languages, the role of classes is overloaded.
Because classes serve as units of reuse, as well as abstract data types,
programmers cannot reuse code at arbitrary places in the class hierarchy.
For small class hierarchies, this is not problematic, but in large
hierarchies it is, resulting in duplicate code.
The Traits inheritance model has been designed to cope with this problem.
Traits are lightweight entities that serve as primitive units of code reuse.
A trait has a name and contains methods, which may have an implementation. A
class can make use a trait, by which it gains the trait's methods. Traits
can also be combined, either by a class or by another trait. Common behavior
can thus be placed in traits, instead of in the class, which allows a way of
code reuse that is unrelated to the class hierarchy.
In the past, there have been other solutions to the problem of code reuse,
such as Multiple Inheritance and Mixins. However, these solutions bring
along new problems, which are explained in the thesis. The traits model has
been designed to avoid these problems.
Until recently, traits had only been implemented for an untyped dialect of Smalltalk.
The goal of this thesis project was to make traits available in Java, a
widespread, and typed programming language. This has been done by extending
Java using an extendible compiler framework.
The resulting language is called JTL (Java Trait Language), and it improves regular Java.