Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I represent a mixin/role/trait with UML properly?

Me and several other developers are currently cleaning up our legacy code base, mostly separating visual and data layers. To help developers not involved in this refactoring understand the model, I'd like to introduce a (rather informal) class diagram with comments about scope and desired usage for each class. Since I'm lazy, I'd like to use UMLGraph for that.

However there is a small problem: we've got a perl code base and the refactoring uses Moose roles extensively. Now I don't know UML good enough to find a proper abstaction for roles -- my first guess would be interfaces, but they also contain implementation; multiple inheritance doesn't quite cut it either.

How do I (or how would you) represent roles properly in a class diagram?

like image 707
Nikolai Prokoschenko Avatar asked Apr 22 '10 11:04

Nikolai Prokoschenko


2 Answers

I'm no UML expert but in the original paper Traits were represented like this

Traits Diagram http://img.skitch.com/20100422-8iey4atkkama53ni81c3pca562.jpg

like image 115
perigrin Avatar answered Nov 05 '22 22:11

perigrin


I would represent a role as a UML class with the «role» stereotype. The class composing the role would then have an association to the role with the stereotype «does».

Simple Composition http://img820.imageshack.us/img820/5665/simplecomposition.png

If I needed to further adapt the role, with aliases or exclusions, I'd create that as an association class with properly annotated members and with the «adaptation» stereotype. The name of the association class wouldn't matter, because it won't be a real type in the design; so I'd leave it unnamed.

Composition with Conflict Resolution http://img828.imageshack.us/img828/244/conflictcomposition.png

(Please note that I have shown the adaptation "class" connected to the composition and the role it adapts. What I really wanted to do was connect it to the association between MyComposition and MyRole1. It's just that the tool I used didn't support association classes).

like image 24
Jordão Avatar answered Nov 05 '22 22:11

Jordão