UML图中的私有嵌套Java类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27146519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:54:20  来源:igfitidea点击:

Private nested Java class in UML diagram

javaumlclass-diagramnested-class

提问by guitar_freak

I have a question regarding UML. I have a class which simply contains an inner class with the private access modifier - cannot be accessed from anywhere else... Normally in order to present an inner class relation I can use a (+) relation like here (InnerOddIterator):

我有一个关于 UML 的问题。我有一个类,它只包含一个带有私有访问修饰符的内部类 - 不能从其他任何地方访问......通常为了呈现内部类关系,我可以使用像这里 ( InnerOddIterator)的 (+) 关系:

enter image description here

在此处输入图片说明

(taken from http://www.uml-diagrams.org/nested-classifier.html)

(取自http://www.uml-diagrams.org/nested-classifier.html

I have not found anywhere any information about how can clearly emphasize that this class is private. Do you know if such a method exist at all? If yes I'll be grateful you give me some link here or something?

我没有在任何地方找到任何关于如何清楚地强调这个类是私有的信息。你知道这样的方法是否存在吗?如果是的话,我会很感激你给我一些链接在这里或什么?

Just to keep things clear, a sample code:

为了让事情清楚,一个示例代码:

public class DataStrucure {
     // fields, methods, etc
     private class InnerOddIterator{
          // ... 
     };
}

回答by Martin Meeser

First of all: You have something in your code and asking for an UML representation. But, IMHO, you should look at it the other way round: How can that UML-idea be represented in code. (Some programming languages don't even offer private nested classes...).

首先:您的代码中有一些内容并要求使用 UML 表示。但是,恕我直言,您应该反过来看:如何在代码中表示 UML 想法。(一些编程语言甚至不提供私有嵌套类......)。

As for private nested classes: I suggest using a Composition. It is stronger as Association but not as strong as inheritance. And the composed class can not exist without its composer. Pretty much exactly a private nested class.

至于私有嵌套类:我建议使用 Composition。它比关联强,但不如继承强。没有它的作曲家,组合类就不能存在。几乎完全是一个私有的嵌套类。

The drawing is taken from http://www.uml-diagrams.org/association.html: enter image description here

该图取自http://www.uml-diagrams.org/association.html在此处输入图片说明

回答by Red Beard

In order to indicate that your inner class is privete the best, for me, is to use - character as depicted below but of course in this case you miss the internal structure of your inner class..enter image description here

为了表明您的内部类是privete 最好的,对我来说,是使用 - 字符如下所示,但当然在这种情况下,您会错过内部类的内部结构..在此处输入图片说明

回答by Vladimir

From UML point of view. If classifier (Class also) is nested in other class, nesting class plays role of namespace. In this case nested classes are hidden (private) in context namespace. it means, your diagram implicitly defines private inner class definition.

从UML的角度来看。如果分类器(Class also)嵌套在其他类中,则嵌套类起到命名空间的作用。在这种情况下,嵌套类在上下文命名空间中隐藏(私有)。这意味着,您的图表隐式定义了私有内部类定义。

here is part of definition from UML Superstructure section structred classifiers:

这是 UML 上层结构部分结构化分类器定义的一部分:

"A class acts as the namespace for various kinds of classifiers defined within its scope, including classes. Nesting of classifiers limits the visibility of the classifier to within the scope of the namespace of the containing class and is used for reasons of information hiding. Nested classifiers are used like any other classifier in the containing class."

“一个类充当其范围内定义的各种分类器的命名空间,包括类。分类器的嵌套将分类器的可见性限制在包含类的命名空间范围内,并且用于信息隐藏的原因。嵌套分类器的使用与包含类中的任何其他分类器一样。”