Is there a representation for modern programming constructs that are becoming common in modern OOP/hybrid languages like mixins/traits/categories/partial classes ?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Yes and no. Generally, UML allows the usage of multiple inheritance, which allows you to model something like traits. In a sense, traits in Scala are a way to allow multiple inheritance, whilst trying to reduce its negative effect (namely, the diamond inheritance problem).
As for the Yes part of the answer: you can show traits/mixins as normal classes in UML, or even add a corresponding stereotype to them (either make them abstract, or if you want to be more precise define your own profile with a proper trait-stereotype). A class that mixes multiple traits is then visualized as a class that inherits from these traits (via generalization associations).
However, the UML has no proper semantic concept of this inheritance. Other than a vague description that the generalization means that the subclass gets the features from its superclasses, you will not get a clean semantics. In particular, language-specific semantics like Scala's trait linearization are not directly supported in UML.
If you want to make a very precise model of your Scala traits/classes, you would need to define a custom UML profile and assign stereotypes to your generalizations to document their linearization order. However, that's limited as well, because the order may be different for different classes that share some of their traits.
So it depends on what you want to use UML for. If you want to use it as documentation, you may well be able to live with these shortcomings. If you want to use UML models as a base for code generation or some such, then newer language features spell trouble. While the UML offers semantic variation points it is as a whole based on the traditional OO languages and falls short as soon, as you leave these standard feature sets. While traits/mixins still relate closely to classes/objects, and hence, can be visualized with some trade-offs, you'll be even more at a loss, when you try to use UML for non-OO language aspects (think, functional or logic programming).