【问题标题】:UML Relationship Type: Variables & Parameters & CloningUML 关系类型:变量和参数 & 克隆
【发布时间】:2014-06-28 02:50:15
【问题描述】:

在 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&lt;B&gt;.

我对每个场景的想法(但我很不确定)

  1. A 类使用 B 类(依赖)[虽然我在这和关联之间折腾]

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

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

  4. 不,D类还是由C类组成的

  5. A 类有 B 类(聚合)

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

感谢您的任何回答

【问题讨论】:

    标签: java class dependencies uml aggregation


    【解决方案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的数据成员,否则只是另一种依赖情况,因为链接是暂时的且持续时间很短(在方法执行期间)

    【讨论】:

    • 谢谢阿列克斯。我没有意识到我的&lt;B&gt; 消失了(我已将它们放在代码块中以便它们保留),但答案涵盖了那里的情况。很有帮助的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    相关资源
    最近更新 更多