Over the last couple of months I’ve spent a bit of time studying Scala, a multi-paradigm (function + oo) programming language designed to inter-operate with both .NET and Java.

One of the (many) neat features of the language is its inclusion of the trait abstract data type. Scala traits are similar to Java interfaces in that they are used to define method signatures for classes in an inheritance hierarchy. In contrast to interfaces, however, they can also include definitions of some of their methods.

trait Similarity {
def isSimilar(x: Any): Boolean
def isNotSimilar(x: Any): Boolean = !isSimilar(x)
}

Traits are not unique to Scala, they have also been tried out in Squeak, Perl and C#.