本文是小编为大家收集整理的关于UML图中的私有嵌套Java类的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我有一个关于UML的问题.我有一个类,该类简单地包含一个带有私人访问修饰符的内部类 - 无法从其他任何地方访问...通常是为了提出内部类关系,我可以使用(+)的关系(+)关系(InnerOddIterator):
(取自 .html )
我还没有找到有关如何清楚地强调该类是私人的任何信息.您知道是否存在这种方法?如果是,我很感激您在这里给我一些链接?
只是为了保持清晰,示例代码:
public class DataStrucure { // fields, methods, etc private class InnerOddIterator{ // ... }; }
推荐答案
从UML的角度来看.如果分类器(也)嵌套在其他类中,则嵌套类将扮演名称空间的角色.在这种情况下,嵌套类是在上下文名称空间中隐藏的(私有).这意味着,您的图隐含地定义了私人内部类定义.
这是UML上层建筑部分的定义的一部分,structred分类器:
"一个类充当其范围内定义的各种分类器的名称空间,包括类. 分类器将分类器的可见性限制为包含类名称空间的范围内,并用于 信息隐藏的原因.嵌套分类器与包含类中的任何其他分类器一样使用."
其他推荐答案
首先:您的代码中有一些内容并要求使用UML表示.但是,恕我直言,您应该以相反的方式看待它:如何用代码表示该UML-IDEA. (某些编程语言甚至不提供私人嵌套类...).
至于私人嵌套类:我建议使用构图.它更强大,但不如继承那么强.如果没有其作曲家,那么组成的班级就不可能存在.几乎完全是一个私人嵌套班.
该图取自 http://www.uml-diagrams.org/association.html :
其他推荐答案
为了表明您的内部类是最好的,对我来说是最好的 - 如下所示,但在这种情况下,您会错过内部类的内部结构.
问题描述
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):
(taken from 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{ // ... }; }
推荐答案
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.
here is part of definition from UML Superstructure section structred classifiers:
"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."
其他推荐答案
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...).
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.
The drawing is taken from http://www.uml-diagrams.org/association.html:
其他推荐答案
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..