gpt4 book ai didi

java - UML关系类型: Variables & Parameters & Cloning

转载 作者:太空宇宙 更新时间:2023-11-04 06:49:06 25 4
gpt4 key购买 nike

在 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>.

我对每种情况的想法(但我非常不确定)

  1. A 类使用 B 类(依赖)[尽管我在这和关联之间犹豫不决]

  2. A 类使用 B 类(依赖)

  3. 是的,A类使用A类(依赖)

  4. 不,D类仍然由C类组成

  5. A 类具有 B 类(聚合)

我的理解完全错误吗?这些场景中正确的关系是什么?

感谢您的回答

最佳答案

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) Is there a relationship line in the UML to itself? Yes, class A uses class A (dependency)

如果类 A 在其数组中具有类 A 的数据成员,则它是与其自身的循环关联。如果不是,则无需放置依赖项 A-->A。无论如何,A 取决于自身,因此它是多余的。

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? No, Class D is still composed of Class 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 的数据成员,否则这只是另一种依赖情况,因为链接是暂时的且短暂的(在方法执行期间)

关于java - UML关系类型: Variables & Parameters & Cloning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23580276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com