1

Since the release of Java 8 you may provide default implementations of methods in interfaces.

I have been looking for a way to realize this in UML but could not find anything on the matter. The case of default implementations in interfaces probably is too special to be adopted to in the UML specs.

But still the Question:

Is there a way to display these default methods in UML?

timbernasley
  • 490
  • 9
  • 21
  • 2
    UML is extendable. Depending on the tool you're using that may be easy to do. But generally speaking UML doesn't (and IMHO shouldn't) include specific language aspects. – ChiefTwoPencils Oct 29 '15 at 09:55

2 Answers2

1

There is nothing special about this situation from UML perspective, that's what stereotypes are for.

UML represents a conceptual model, which is not tied to a language-specific situation, so you can model it for example in this way:

enter image description here

How such model will be implemented is different matter. In Java you could use interfaces, in C++ (which doesn't have interfaces) you would abstract classes, in Ruby you might take a yet different approach, but the model can** still be the same.

**By can I mean that it is common practice to commit to a particular language already at the modeling level, so one would alter to model to better fit the target language.

Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
1

There are three types of methods within an interface in java 8:

  1. static
  2. default
  3. abstract

Abstract methods are generally italic

+ sayAbstract() : void

Static methods are generally u̲n̲d̲e̲r̲l̲i̲n̲e̲d̲:

+̲ ̲s̲a̲y̲S̲t̲a̲t̲i̲c̲(̲)̲ ̲:̲ ̲v̲o̲i̲d̲

Since default methods are a sort of instance methods, format them accordingly:

+ sayDefault() : void

Sabine
  • 323
  • 4
  • 14
  • But nobody puts abstract methods in an interface in italic (nor does the standard), so having default methods in a regular font will not distinguish them from abstract interface methods – Catweazle Oct 22 '20 at 15:16