next up previous contents index
Next: 3.4 Control-flow Up: 3 The Slate World Previous: 3.2 Core Behaviors   Contents   Index

3.3 Traits

Slate objects, from the root objects down, all respond to the message traits, which is conceptually shared behavior but is not as binding as a class is. It returns an object which is, by convention, the location to place shared behavior. Most Slate method definitions are defined upon some object's Traits object. This is significant because cloning an object with a traits delegation slot will result in a new object with the same object delegated-to, so all methods defined on that traits object apply to the new clone.

Traits objects also have their own traits object, which is Traits traits. This has the important methods defined on it for deriving new prototypes with new traits objects:

myObject derive &mixins: &rejects:
will return a new clone of the object with a traits object which is cloned from the original's traits object, and an immutable delegation slot set between the traits objects. If mixins are given, it will include more immutable delegation links between the new traits and the traits of the array's objects, in the given order, which achieves a structured, shared behavior of static multiple delegation. Note that the delegation link addition order makes the right-most delegation target override the former ones in that order. One interesting property of this method is that the elements of the mixins do not have to be Derivable.
obj addPrototype: name derivedFrom: parentsArray
will perform the effects of either derive using all the elements of the Sequence in the same order as derive. It also assigns the name to the traits object's name attribute as well as using the name for the attribute between the surrounding object and the new prototype. Finally, it will compare the delegation pattern of the new object with the old, and only replace the old if they differ. In either case, the installed object is what is returned.
As with any method in Slate, these may be overridden to provide additional automation and safety in line with their semantics.


next up previous contents index
Next: 3.4 Control-flow Up: 3 The Slate World Previous: 3.2 Core Behaviors   Contents   Index
Brian Rice 2004-10-30