开发者

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

开发者 https://www.devze.com 2022-12-27 23:56 出处:网络
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

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 lik开发者_如何学Ce 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?


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

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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消