-2

So I have the following case. I have an interface A and an implementation AImpl. Now I have another implementation of A, called A2Impl, which references any instance of A besides implementing A already.

So I have now drawn the following UML class diagram:

enter image description here

Would this be correct? How do i draws this correctly?

11
  • 1
    Which UML notation are you implementing? Implement, extends and composition are drawn with different line styles and arrows.
    – Laiv
    Commented Jun 5, 2019 at 9:43
  • i am using whatever is on the english wikipedia article for class diagrams
    – Marcel
    Commented Jun 5, 2019 at 9:50
  • Well, the answer to the question is yes you can draw such a relationship between A, AImpl and A2Impl but for the sake of the "readability" do use the proper notation to represent the different kinds of associations.
    – Laiv
    Commented Jun 5, 2019 at 9:56
  • So, I took a look at this: en.m.wikipedia.org/wiki/Class_diagram
    – Marcel
    Commented Jun 5, 2019 at 10:00
  • Check the first image in "Relationships".
    – Marcel
    Commented Jun 5, 2019 at 10:01

1 Answer 1

3

Yes, it is correct, but not optimal.

The dependency just says 'A2Impl' cannot do without 'A', but that is obvious, since A2Impl implements A. In fact, the 'implements' relationship implies the dependency.

If A2Impl has a permanent reference to another instance of A, it would be better to replace the dependency by an association (an arrow with a solid line instead of a dashed line). You may wish to add multiplicities to the association (not mandatory). In the figure below, I have specified multiplicity "1" to indicate that every instance of A2Impl always refers to exactly one instance of A.

cd

If you think an association is not appropriate, you could also assign a stereotype to the dependency, to indicate the type of dependency, e.g. «call».

Not the answer you're looking for? Browse other questions tagged or ask your own question.