3

How to present the association composition of an anonymous class defines in the class itself in the UML 2?

Thanks

Aguid
  • 943
  • 2
  • 10
  • 24
  • 1
    It seems to be a common misunderstanding of the purpose of UML, that every class has to be included in a diagram. It’s a *documentation* tool, at least in the original purpose, and anonymous inner classes are obviously something not worth being documented. If used correctly… – Holger Jan 13 '17 at 20:10

1 Answers1

5

In either of the shown ways:

enter image description here

See also p. 716 and 12.2.4 Notation on p. 246 for the nesting connector.

As @JimL. suggests, an anonymous class has no name. It would look like this:

enter image description here

However, it does not make much sense to use anonymous classes in a model for obvious reasons. Honestly, I don't know any programming language which permits anonymous classes, but there are probably such. From what I estimate they are just syntactic sugar to ease certain programming tasks. And for that reason (too) they should not be modeled. (Just my few cents here)

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • Thanks, What about the anonymous ? I found the following link talking about nested but no reference to anonymouse :( http://www.sparxsystems.com/resources/uml2_tutorial/uml2_classdiagram.html Thanks again – Aguid Jan 12 '17 at 15:55
  • Rename "Class1" to "", but add a generalization or realization arrow to state what this class specializes or implements. – Jim L. Jan 12 '17 at 17:14
  • @JimL. Uhm, what? I have no idea what you mean. Your text seems to be truncated too. – qwerty_so Jan 12 '17 at 20:06
  • An anonymous inner class must be nameless, and it has to be a subclass or implementation of _something_. – Jim L. Jan 12 '17 at 20:08
  • @JimL. Ah, ok. I'll just wait for the OP to give feedback if this is what he's looking for, since it almost translates like it. – qwerty_so Jan 12 '17 at 20:22
  • He already asked, "what about the anonymous?", in the first comment here. – Jim L. Jan 12 '17 at 20:24
  • @JimL. Oh. I missed that. I just came back and only noticed your comment :-( – qwerty_so Jan 12 '17 at 20:27
  • @JimL. I have added your suggestion with a short comment. You wrote _rename "Class1" to ""_ but I guess you meant _rename "Inner" to ""__ as this is the anonymous inner class the OP asked about. – qwerty_so Jan 12 '17 at 21:16
  • The first diagram has the containment line backwards on the right-hand side. – Jim L. Jan 12 '17 at 21:21
  • @JimL. I probably again got hick-ups from the specs, reading **12.2.4 Notation** on p. 246. I also used it the other way around all time (if ever). But I interpreted that paragraph like shown above. I'll happily return to my old notation if you confirm, the above is wrong. Thanks and cheers. – qwerty_so Jan 12 '17 at 22:21
  • §12.2.4 says, "Members may also be shown by branching lines to member elements, drawn outside the package. A plus sign (+) within a circle is drawn at the end attached to the Package." Figure 12.5 also shows `Types` containing `Shape` and `Point`, not the other way around. – Jim L. Jan 12 '17 at 22:25
  • @JimL. Ah. I just should have scrolled down a bit :-( Honestly, those texts from the spec are really hard to digest for a non-native speaker. _the end attached to the Package_ , yes, but which? This is a lot of guesswork >:-( – qwerty_so Jan 12 '17 at 22:32
  • I don't understand the ambiguity in "A plus sign (+) within a circle is drawn at the end attached to the Package." But yes, specs are not written as primers. I don't have the patience to read the spec cover to cover, and I still discover new things. One crutch I use is that MagicDraw is probably the most conformant to the standard. It's a quick way to sanity check a detail before checking the spec. – Jim L. Jan 12 '17 at 22:38
  • @JimL. I use EA for that purpose which isn't too bad either. Of course it still does not tell which way to draw this nasty nesting connector. Thanks for taking the time here. – qwerty_so Jan 12 '17 at 23:12
  • I had heard they're not very compliant. Anyway, you can easily drag a package onto a diagram in MagicDraw and tell it to draw missing lines. That shows the containment lines as expected. – Jim L. Jan 12 '17 at 23:16
  • @JimL. It really looks like a solid product. But I'm retired and don't have the bucks available. EA is about 1/10th of that price and not that bad as you might have been told. Still using it for more than 10 years despite it's awkward UI. – qwerty_so Jan 12 '17 at 23:53
  • Java has anonymous classes. But I agree that they (usually) should not be modeled. If there really is a permanent association that should be documented, it should refer to the type that the anonymous class extends. As the formal type of the member establishing the association will also refer to that type. – Holger Jan 13 '17 at 20:14
  • Thank you for taking time to discuss this point, your comments are so helpfull for me. I am also agree with Holger that they should not be modeled because they are so detailled and done for specific need. – Aguid Jan 16 '17 at 09:02