Stateful Traits and their Formalization - Archive ouverte HAL Accéder directement au contenu
Article Dans Une Revue Computer Languages, Systems and Structures Année : 2008

Stateful Traits and their Formalization

Résumé

Traits offer a fine-grained mechanism to compose classes from reusable components while avoiding problems of fragility brought by multiple inheritance and mixins. Traits as originally proposed are stateless, that is, they contain only methods, but no instance variables. State can only be accessed within stateless traits by accessors, which become required methods of the trait. Although this approach works reasonably well in practice, it means that many traits, viewed as software components, are artificially incomplete, and classes that use such traits may contain significant amounts of boilerplate glue code. We present an approach to stateful traits that is faithful to the guiding principle of stateless traits: the client retains control of the composition. Stateful traits consist of a minimal extension to stateless traits in which instance variables are purely local to the scope of a trait, unless they are explicitly made accessible by the composing client of a trait. We demonstrate by means of a formal object calculus that adding state to traits preserves the flattening property: traits contained in a program can be compiled away. We discuss and compare two implementation strategies, and briefly present a case study in which stateful traits have been used to refactor the trait-based version of the Smalltalk collection hierarchy.
Fichier principal
Vignette du fichier
Berg08e-JournalComputerLanguages-StatefulTraitsFormalization.pdf (531.21 Ko) Télécharger le fichier
Origine : Fichiers produits par l'(les) auteur(s)
Loading...

Dates et versions

hal-02109190 , version 1 (24-04-2019)

Identifiants

Citer

Alexandre Bergel, Stéphane Ducasse, Oscar Nierstrasz, Roel Wuyts. Stateful Traits and their Formalization. Computer Languages, Systems and Structures, 2008, 34 (2-3), pp.109-129. ⟨10.1016/j.cl.2007.05.005⟩. ⟨hal-02109190⟩
80 Consultations
146 Téléchargements

Altmetric

Partager

Gmail Facebook X LinkedIn More