Often, when modelling a system there are properties and operations that are related to a group of objects rather than to a single object. In this paper we extend Java with Swarm Behavior, a new com- position operator that associates behavior with a collection of instances. The lookup resolution of swarm behavior is based on the element type of a collection and is thus orthogonal to the collection hierarchy.
Traits @cite_7 are collections of methods (behavior) that can be composed into classes. Traits are normally seen as entities that are composed by the developer when designing the system. More dynamic notions of traits have been explored where traits are installed or retracted at runtime @cite_2 . As traits are applied to classes, they provide behavior to all instances of the class, similar to normal methods. Thus traits alone do not help to model behavior of a collection of objects. It would be interesting to explore a combination of traits with . Traits could be used to structure the . As classes are composed of traits, groups could be composed from traits to support reuse and limit code-duplication.
@cite_7 @cite_2
2111898165 26503509
Inheritance is well-known and accepted as a mechanism for reuse in object-oriented languages. Unfortunately, due to the coarse granularity of inheritance, it may be difficult to decompose an application into an optimal class hierarchy that maximizes software reuse. Existing schemes based on single inheritance, multiple inheritance, or mixins, all pose numerous problems for reuse. To overcome these problems we propose traits, pure units of reuse consisting only of methods. We develop a formal model of traits that establishes how traits can be composed, either to form other traits, or to form classes. We also outline an experimental validation in which we apply traits to refactor a nontrivial application into composable units. On the one hand, traits are a powerful way of structuring classes. Traits support the reuse of method collections over several classes. However, traits cannot be used when specifying unanticipated changes to an application. On the other hand, classboxes are a new module system that supports the local redefinition of classes: a collection of classes can be locally extended with variables and or methods and the existing clients do not get impacted by changes. However, an extension applied to a class by a classbox cannot be reused for other classes. This paper describes how combining Traits and Classboxes supports the safe introduction of crosscutting collaborations: safe because the existing clients of the classes do not get impacted, crosscutting because collaborations between several classes can be put in place in a unanticipated manner. In the resulting system, a collaboration is represented by a classbox and a role by a trait.