UML Representing an anonymous class in a class diagram?

How to represent an anonymous Java class in a UML class diagram?

+6
source share
3 answers

Inner (nested) classes are represented in UML with an association decorated with a crossed circle.

Illustration:

UML inner class http://www.informit.com/content/images/chap3_0131428489/elementLinks/03fig22.gif

A source:

+20
source

There are two truly anonymous classes in Java. First, this is an unnamed inner class. For instance:

class BGThread<T>{...} ... class TitleEditDlg{ new BGThread<Props>(cont, true) { @Override public Props run() { ... } } } 

Quote from the UML 2.5 standard (p.149):

Standard notation for an anonymous instance. Specification unnamed Classifier - underlined colon (':).

So, as for the anonymous java class, you have to create a class block with the name : as a name and connect the container class to it twice - relative to the container and the unidirectional arrow without a dot. On the other hand, a block : must connect to the parent class.


According to the same source, Anonymous Bound Class , that is, the second anonymous class that we meet in Java, but often do not notice it when you use a template / common class, as in

 class BGThread<T>{...} ... class TitleEditDlg{ BGThread<String> newThread= new BGThread<String>(); } 

can be displayed in two ways:

  • As a bind addiction, with a replacement for it.
  • As an intermediate class, with the name of the parent class and substitution in angle brackets. Please note: here the class is anonymous, but the attribute has a name. So this way you show more information.

enter image description here

+3
source

I was looking for a way to represent a literal of a JavaScript object in a class diagram (I know this doesn't make much sense ...) and I found this post.

I would sacrifice this link and image. Ciao.

http://www.uml-diagrams.org/class-diagrams.html

enter image description here

0
source

Source: https://habr.com/ru/post/921578/


All Articles