How would one represent a Java anonymous class in a UML class diagram?
Inner (nested) classes are represented in UML with an association adorned with a crossed circle.
There are two really anonymous classes in Java First is the non-named inner class. Such as:
class BGThread<T>{...}
...
class TitleEditDlg{
new BGThread<Props>(cont, true) {
@Override
public Props run() {
...
}
}
}
A citation from UML standard 2.5 (p.149):
The standard notation for an anonymous InstanceSpecification of an unnamed Classifier is an underlined colon (‘:’).
So, as for anonymous java class, you should create a class block with only :
as name and connect the container class to it twice - by container relationship and by one-direction arrow without a dot. From the other side, the :
block should connect to the parent class.
According to the same source, an Anonymous Bound Class
, that is the second anonymous class we meet in Java, but often do not notice it, when you use a template/generic class, as in
class BGThread<T>{...}
...
class TitleEditDlg{
BGThread<String> newThread= new BGThread<String>();
}
can be shown by two ways:
bind
dependency, with substitution on it.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With