简体   繁体   中英

How to express dependency in a UML Class Diagram?

I the following two classes:

class a {
    void foo(){
        b object= new b();
        object.baar();
    }
}
class b {
    void baar(){
    }
}

How to express class a using class b with Class Diagram (which arrow to use)?

You would need to put a dashed dependency line, which may be directional or not.

  • If class b makes use of class a , the dependency line should be bidirectional (or directionless)
  • If class b does not make use of class a (except possibly through callbacks not tied directly to a ) make the dashed line directional from a to b .

插图

Whenever one class has a reference/uses another, it is said to have a dependency on it. In your example, class a uses class b . Therefore class a has a dependency on class b . For that, you can use the UML dashed line with open arrow as described here .

This is a very general relationship.

One class depends on another if the independent class is a parameter variable or local variable of a method of the dependent class.

If your class a had an instance variable, you would use the association link instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM