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

问题描述

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

解决方案

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

请注意,这意味着在调用 doA 之前,:Register 对象设法通过标准方式访问单例,例如,getInstance().这使图表更加灵活.

对于类图:

如何在 UML 中将类标记为单例?-LMLPHPI 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 中将类标记为单例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 10:05
查看更多