Search code examples
dependenciesumlclass-diagrambidirectional-relation

It is possible to use bidirectional dependency in UML class diagram?


I have 2 classes, they are more complex but that is not important.. How should I draw this dependency in UML class diagram ? I'm not sure how it should look like

public class A {
  private void foo(B b){
   ....
  }
  ...
}

public class B {
  private void foo(A a){
   ....
  }
   ....
}

could I draw something like this ? or how should it look like ? enter image description here


Solution

  • This is perfectly ok. You can alternatively use a single bi-directional dependency.

    enter image description here

    P.S. From a design perspectice I don't think it's so ok. Having dependencies in both directions means your design should be revised. a A dependency should go only in one direction. Cross-dependencies are just a cause for trouble. See also circular dependency.