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 - Composable Units of Behavior
[go: Go Back, main page]

SCG Home Page Research Resources Teaching Archive People

Research.gif SCG
	    Resources Banner

Traits — Composable Units of Behavior

We have been developing a simple compositional model for structuring object-oriented programs, which we call traits. Traits are essentially groups of methods that serve as building blocks for classes and are primitive units of code reuse. In this model, classes are composed from a set of traits by specifying glue code that connects the traits together and accesses the necessary state.

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

We have implemented traits in Squeak, an open-source Smalltalk-80 dialect.

Papers

The following papers give an overview of traits and show its practical usability. The first paper in the list, "Traits — Composable Units of Behavior", is the concept paper introducing the Traits model and we recommend to read it first.

  • Traits — Composable Units of Behavior is the concept paper that introducing Traits. It also compares traits to mixins and multiple inheritance, summarizes a formal model for traits, briefly discusses our implementation and gives an overview of a realistic application: refactoring the Smalltalk collection hierarchy.
  • Applying Traits to the Smalltalk Collection Hierarchy is an experience report of applying traits to refactor the Smalltalk collection hierarchy. Although this refactoring was rather successful, the exact details of the refactored hierarchy are not the most important aspect of this paper. It is more important to communicate how traits can be used in practice and to give the reader a feeling for traits and to show how traits can be used in a real language.
  • Traits: The Formal Model presents a formal model for traits and defines some basic properties of traits and classes.

Implementations

Squeak

A prototype version of traits in Squeak is available for download. See the traits prototype page for more information.

In addition, we are preparing a Squeak changeset that allows to file in a more stable version of traits into the latest Squeak image.

Visual Works

The developers of VisualWorks Smalltalk are very interested in incorporating traits into VisualWorks. They plan to build a working traits prototype that should be available somtime in 2003.

Last modified: 2003-08-19