在UML类图中表示或暗示getter和setter的快捷方式 [英] Shortcut for denoting or implying getters and setters in UML class diagrams

查看:690
本文介绍了在UML类图中表示或暗示getter和setter的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UML类图中,如果一个类具有5个需要可变和可读的私有属性,则即使没有该类的任何有趣功能,UML也将具有10个get / set方法的外观非常难看:





除了丑陋之外,我觉得UML应该专注于该类更有趣的功能。我是正确的吗?



是否存在一些用于表示或暗示私有属性的获取器和设置器的标准捷径?

解决方案

您是正确的:不需要在标准设置方法和获取方法的样板签名中包含(噪声)类模型。不幸的是,UML没有为隐含私有属性的getter和setter定义标准符号。因此,您必须使用自己的约定。例如,您可以将一般说明(所有私有属性都具有getter和setter,而私有只读属性仅具有getter)作为UML Comment ,显示为右上角的矩形弯曲(也称为注释符号)。



如果您希望使相关属性的getter / setter约定更加明确,请创建您的自己的构造型(例如,获取/设置和获取)将用于对这些私有财产进行分类,如下图所示:





我还使用它来描述/记录ECMAScript 6类的隐式获取器和设置器。


In a UML class diagram, if a class has 5 private attributes that need to be mutable and readable, the UML gets pretty ugly with 10 get/set methods even without any of the class' interesting functionality:

Ugliness aside, I feel like the UML should focus on the class' more interesting functionality. Am I correct?

Is there some standard shortcut for denoting or implying getters and setters for private attributes?

解决方案

You are correct: there is no need to include the (noise of) "boilerplate" signatures of standard setters and getters in a class model. Unfortunately, UML does not define a standard notation for implying getters and setters for private attributes. So, you'd have to use your own convention. For instance, you could include a general explanation (that all private properties have getters and setters, while private read-only properties have only getters) as a UML Comment, shown as a rectangle with the upper right corner bent (also called a "note symbol") attached to the diagram.

If you prefer to make the getter/setter convention more explicit for the properties concerned, then create your own stereotypes (e.g., «get/set» and «get») to be used for categorizing these private properties, as shown in the following diagram:

I'm also using this for describing/documenting the implicit getters and setters of ECMAScript 6 classes.

这篇关于在UML类图中表示或暗示getter和setter的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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