Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
Traits
[go: Go Back, main page]

Downloads

Traits — Composable Units of Behavior

Traits are a simple composition mechanism for structuring object-oriented programs. A Trait is essentially a parameterized set of methods; it serves as a behavioral building block for classes and is the primitive unit of code reuse. With Traits, classes are still organized in a single inheritance hierarchy, but they can make use of Traits to specify the incremental difference in behavior with respect to their superclasses.

Unlike mixins and multiple inheritance, Traits do not employ inheritance as the composition operator. Instead, Trait composition is based on a set of composition operators that are complementary to single inheritance and result in better composition properties.

We have implemented Traits in Squeak, an open-source Smalltalk-80 dialect. In the meantime, Traits have had a significant practical impact and have been ported to various other languages.

Papers

The following papers give an overview of Traits and show their practical usability. Note that the material of all these papers and more is also available in Nathanael Schärli's dissertation Traits — Composing Classes from Behavioral Building Blocks.

Implementations

Squeak Smalltalk

Our prototype version of Traits in Squeak is available for download. In addition, we are working on a clean and stable version of Traits in Squeak. The latest version is available from SqueakMap.

Perl

Stevan Little implementated Traits in Perl 5. In his series about the unfolding of the Perl 6 design, Larry Wall, the creator of Perl, gives a description of Roles, the variation of Traits that is planned as a fundamental language element of Perl 6.

Scala

Scala is a modern multi-paradigm programming language that smoothly integrates features of object-oriented and functional languages. Scala also features Traits, which is particularly interesting because they are smoothly integrated into Scala's static type system (which is similar to the type system of Java and C#).

Rotor

We are currently working on a Microsoft funded research project aimed to bring Traits to C#/Rotor, the shared source implementation of .NET.

VisualWorks Smalltalk

Terry Raymonds from Cincom ported a variation of Traits to VisualWorks Smalltalk.

2005-07-13