In Java it's perfectly legal for an interface to extend an interface. Does this relationship in UML look like an "extends" relationship (solid line, closed, unfilled arrowhead) or an "implements" relationship (dotted line, close, unfilled arrowhead)? I can't seem to find an example of this relationship either online or in Fowler's book.
Asked
Active
Viewed 2.0k times
1 Answers
41
Use "extends" (solid line, closed, unfilled arrowhead), which is consistent with how Java uses the extends
and implements
keywords.
- "extends" == UML generalization / specialization relationship
- "implements" == UML realization relationship
The sub-interface is a specialization of the super-interface, not a realization of it.
See http://www.informit.com/articles/article.aspx?p=29224&seqNum=2
.
-
5hehe, what a beatiful diamond:) – Gabriel Ščerbák Apr 23 '10 at 10:50
-
@Gabriel - *heh* - it is a nice diagram. I wish I could take credit for it, but its from the referenced article, so credit to Stephen R. Palmer. – Bert F Apr 23 '10 at 13:11
-
4@Bert F I was trying to hint at the diamond inheritance problem:) – Gabriel Ščerbák Apr 23 '10 at 13:15
-
@Gabriel - lol - I'm dense. Doesn't apply to Java interfaces though, right? – Bert F Apr 23 '10 at 13:34
-
@Bert F I was not sure myself, according to this: 9.3.2.1 Ambiguous Inherited Fields it is a problem, which at least gets resolved at compile time. But I have no idea if this holds for methods. – Gabriel Ščerbák Apr 23 '10 at 13:40
-
@Gabriel - very interesting! I wasn't aware of that issue. Thanks for the pointer. – Bert F Apr 23 '10 at 15:56
-
Regarding the (or a cousin of) diamond problem, if interface A contains method `void someMethod()` and interface B contains method `String someMethod()` then a *uh-oh moment* triggers. Note that the problem is the return type; if the return type is also the same then all is well. – Daniel Jan 06 '15 at 18:28