我完全理解代码,但是我在理解与代码相关的 UML 时遇到了一些困难。
问题 1 - 如果我有课
public class one
{....}
public class two
{
one ob;
public two(){ob=new one();}
}
我知道这是一个关联,但我是否在类图中用箭头显示它?
问题 2 - 如果我有以下类(class)
public class three
{
public three(){.........}
public void method() { one obt=new one(); }
}
这是三级和一级之间的关联吗?我不确定,因为它是从该方法应用的。
最佳答案
I know this is an association but do I show this in a class diagram with an arrow or not?
如果类one
没有对类two
的引用,那么你应该有一个箭头。但它从 two
指向 one
(与显示方式相反)。原因:箭头表示可导航性。类 two
可以导航到类 one
,因为它拥有一个实例。相反的情况则不然。从技术上讲,它应该是一个开放的箭头,而不是您使用的封闭形式。
Is this an association between class three and class one? I'm not sure since its being applied from the method.
如果从 two
到 one
的唯一引用是作为方法参数,那么您很可能会显示为依赖项而不是关联。关联声明实体之间的系统关系 - 就像由订单行
组成的采购订单
。在最常转换为成员变量(或其集合)的代码中。依赖关系是比关联更弱的关系形式,并不意味着系统链接。
第h。
关于java - UML 与代码的关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13558225/