2

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

Pauli
  • 538
  • 8
  • 22

2 Answers2

6

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.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • I have added the methods in the picture as in the OP's edited question (just see that my pic shows them public - guess that's ok ;-) – qwerty_so Apr 19 '15 at 16:51
1

It seems to me you have Aggregation. See more details here. But if it is really just dependency you can use the arrow the way did.

Plamen G
  • 4,729
  • 4
  • 33
  • 44
  • 1
    This can't be an aggregation since you can not construct two elements that aggregate each other. How would you construct elements that can only be constructed if the aggregated part was already existent? – qwerty_so Apr 19 '15 at 16:47
  • 1
    @Thomas Kilian, it seemed a bit illogical to me in first place and decided to point this out. Otherwise you are correct. If it was composition it could have been bidirectional but bidirectional aggregation doesn't make sense. – Plamen G Apr 19 '15 at 18:02