如何在 UML 中将类标记为单例? [英] How do I mark a class as a singleton in UML?

查看:33
本文介绍了如何在 UML 中将类标记为单例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UML 图,我想在上面将一些类标记为单例(因为它们是).我怎么做?我是要发明一种新的刻板印象,还是只是添加评论,或者是否有一些现有的方法可以做到这一点?

解决方案

Craig Larman 的应用 UML 和模式"一书(第 3 版)给出了序列图的以下符号:

> </p><p>请注意,这意味着在调用 <code>doA</code> 之前,<code>:Register</code> 对象设法通过标准方式访问单例,例如,<code>getInstance()</代码>.这使图表更加灵活.</p><p>对于类图:</p><p><img src=I have an UML diagram on which I want to mark some classes as singletons (because they are). How do I do that? Do I invent a new stereotype or do I just add a comment or are there some existing means to do that?

解决方案

Craig Larman's "Applying UML and Patterns" book (3rd edition) gives the following notation for a sequence diagram:

Note that it implies that before calling doA the :Register object manages to get access to the singleton via the standard way, e.g., getInstance(). This makes the diagram more agile.

For a class diagram:

这篇关于如何在 UML 中将类标记为单例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆