Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 216
Kristopher Peter Avatar asked Dec 16 '22 08:12

Kristopher Peter


2 Answers

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.

Illustration

like image 76
Sergey Kalinichenko Avatar answered Dec 30 '22 03:12

Sergey Kalinichenko


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.

like image 24
Sotirios Delimanolis Avatar answered Dec 30 '22 01:12

Sotirios Delimanolis