是否关联意味着UML的依赖? [英] Does an association imply a dependency in UML?

查看:123
本文介绍了是否关联意味着UML的依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的<讨论href=\"http://stackoverflow.com/questions/1142339/uml-association-understanding-problem/1142436#1142436\">answer这个<一个href=\"http://stackoverflow.com/questions/1142339/uml-association-understanding-problem/1142436\">question,有一些分歧如何将此code型:

In discussion about my answer to this question, there was some disagreement over how to model this code:

public class MainClass
{
    private Something something;

    public void Action()
    {
        OtherClass other = something.GetOtherClass();
    }
}

要点是:


  1. 的东西类是在 MainClass 属性,这意味着一个协会

  2. 的东西类中的 MainClass 引用,这依赖
  3. 依赖关系应该是一个专门的协会

  1. the Something class is an attribute in MainClass, suggesting an association
  2. the Something class is referenced within MainClass, suggesting a dependency
  3. A dependency is supposed to be a specialised association

然而,由于依赖关系是其中的供应商类不是一个属性,使用的是依赖隐藏的意图是,的东西是一个不能够在情况合适属性,而不是简单地引用

However, since a dependency is can be appropriate in cases where the supplier class is not an attribute, does using a dependency "hide" the intention that the Something is an attribute, rather than simply referenced?

此外,没有一个协会,从而重新presents在一个类的属性,暗示的依赖,因为它被存储(和presumably引用,并以某种方式使用)。

Furthermore, does an association, which represents an attribute in a class, imply a dependency because it is being stored (and presumably referenced and used in some way).

所以,参照上述各点,并关联意味着依赖,以及你将如何在类图模型上面code?

So, with reference to the above points, does an association imply a dependency, and how would you model the above code in a class diagram?

推荐答案

相关性和关联是两个不同的概念。根据UML元,两者都是关系元类的两个独立的子类。

Dependencies and associations are two different concepts. According to the UML metamodel, both are two independent subclasses of the "Relationship" metaclass.

但是,这是事实,在您的情况我只是模型两班,而不是依赖之间的关联。这两个类是通过关联的连接实际上已经使他们依赖。

However, it is true, that in your scenario I'd just model an association between the two classes and not a dependency. The fact that the two classes are connected through an association already make them dependent.

这篇关于是否关联意味着UML的依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆