如何用 UML 正确地表示 mixin/角色/特质?

发布于 2024-08-30 01:00:23 字数 284 浏览 1 评论 0原文

我和其他几位开发人员目前正在清理我们的遗留代码库,主要是分离视觉层和数据层。为了帮助未参与此重构的开发人员理解模型,我想引入一个(相当非正式的)类图,其中包含有关每个类的范围和所需用法的注释。因为我很懒,所以我想使用 UMLGraph 来实现这一点。

然而有一个小问题:我们有一个 Perl 代码库,并且重构广泛使用了 Moose 角色。现在我对 UML 的了解还不够好,无法为角色找到合适的抽象——我的第一个猜测是接口,但它们也包含实现;多重继承也并不能完全解决这个问题。

我(或者你将如何)如何在类图中正确地表示角色?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

简单气质女生网名 2024-09-06 01:00:23

我不是 UML 专家,但在 原始论文 中,特征是这样表示的

< a href="http://img.skitch.com/20100422-8iey4atkkama53ni81c3pca562.jpg" rel="noreferrer">性状图 http://img.skitch.com/20100422-8iey4atkkama53ni81c3pca562.jpg

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

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

对你的占有欲 2024-09-06 01:00:23

我会将角色表示为具有 «role» 构造型的 UML 类。然后,组成角色的类将与具有构造型 «does» 的角色关联。

简单构图 http://img820.imageshack.us/img820/5665/simplecomposition.png< /a>

如果我需要使用别名或排除进一步调整角色,我会将其创建为具有正确注释的成员和 «adaptation» 构造型的关联类。关联类的名称并不重要,因为它不是设计中的真实类型;所以我不会命名它。

解决冲突的组合 http://img828.imageshack.us/img828/244/conflictcomposition。 png

(请注意,我已经显示了与构图相关的适应“类”及其适应的角色。我真正想做的是将其连接到 MyComposition 和 < code>MyRole1。只是我使用的工具不支持关联类)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文