在UML图中,这些场景的关系是什么?
1. Take 2 classes, class A and class B. There are methods in Class A such as:
public function (ArrayList<B>)
public function2 (): ArrayList<B>
2. Take 2 classes, class A and class B. There are methods in Class A such as:
public function (ArrayList<B>)
public function2 (B)
3. Take 1 class, class A. There are methods in Class A to clone itself by using details of the parent, such as:
public clone (): A
public A (A parent)
Is there a relationship line in the UML to itself?
4. Take 2 classes, class C and class D. Class D is an aggregate of class C (C has D). Class D however has a clone function in the same way as Q3 above. Does this mean Class D is not composed of class C?
5. Take 2 classes, class A and class B. There is a method in Class A which have variables that create ArrayList<B>.
我对每个场景的看法(但我不太确定)
A类使用B类(依赖)[虽然我在这个和协会之间折腾]
A类使用B类(依赖)
是的,A类使用A类(依赖)
不,D类仍然由C类
A类有B类(聚合)
我的理解完全错了吗?这些情景中的正确关系是什么?
感谢您的回答
答案 0 :(得分:1)
Take 2 classes, class A and class B. There are methods in Class A such as: public function (ArrayList) public function2 (): ArrayList class A uses class B (dependency) [although I'm tossing up between this and association]
如果ArrayList由B的实例组成,那么它的依赖关系A - > B。如果A中存在类型B的数据成员,那么它将是一个关联(在其中一个变体中)。
不同之处在于依赖关系更通用,并描述了这两者之间的弱连接(通常是短时间连接)(就像这里A中B类型的方法参数一样)。关联意味着更强大,更持久的关系,通过代码级别的数据成员表达。
Take 2 classes, class A and class B. There are methods in Class A such as: public function (ArrayList) public function2 (B) class A uses class B (dependency)
与之前的情况相同,这里很清楚B是方法参数。
Take 1 class, class A. There are methods in Class A to clone itself by using details of the parent, such as: public clone (): A
public A(A parent)UML中是否存在关系线? 是的,A类使用A类(依赖)
如果类A具有其数组的类A的数据成员,则它是与其自身的循环关联。如果不是,则不需要依赖A - > A。 A无论如何都取决于它自己,所以这将是多余的。
选择2个班级,C班和D班.D班是聚合的 C级(C有D)。但是,D类具有相同的克隆功能 方式如上面的Q3。这是否意味着D类不是由C类组成的? 不,D类仍然由C类组成
是。
Take 2 classes, class A and class B. There is a method in Class A which have variables that create ArrayList. class A has class B (aggregation)
不,除非在A中也存在B的数据成员,否则它只是依赖的另一种情况,因为链接是暂时的且持续时间短(在方法执行期间)