'Interfaces in UML class diagrams - should realizations also show interface operations?
I've been doing a lot of work with UML class diagrams lately, and I'm trying to get clarification on a question.
Let's say I declare an interface on my class diagram - let's call it ISomething. On the interface, I declare an operation called doSomething(). I then proceed to create a new class that realizes the interface, called SomethingImpl.
Now, the question that I'm trying to answer is this - should the SomethingImpl class on the diagram also show the doSomething() operation, or can it be left out because its existence is implied?
I've tried to find answers online, but with no luck. The diagrams that I've seen are very inconsistent in this regard - some of the show interface operations on realizations and some don't. As long as my diagrams make sense and clearly express intent, I'm not too concerned about being 100% correct. However, I am curious about this particular scenario.
Solution 1:[1]
It depends, like always.
What you show on a diagram is intended for a certain audience. Now, if that audience is already enlightened and knows the context you can leave out details. If not you are better served showing them. Anyhow, what I do generally is to create overview diagrams with less details and then add various detail diagrams. Depending on your UML tool (I use Enterprise Architect) it is possible to connect elements with a diagram the opens when it's double clicked. This diagram is then element-centered with detail information.
Solution 2:[2]
The class you create might implement only a part of the interface's operations, e.g. in Java could be an abstract class or even a concrete class if the not implemented operations have a default implementation (Java 8 or newer). So, for at least these situations you might want to list the actual implemented operations.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | qwerty_so |
| Solution 2 | Adrian |
