Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private nested Java class in UML diagram

I have a question regarding UML. I have a class which simply contains an inner class with the private access modifier - cannot be accessed from anywhere else... Normally in order to present an inner class relation I can use a (+) relation like here (InnerOddIterator):

enter image description here

(taken from http://www.uml-diagrams.org/nested-classifier.html)

I have not found anywhere any information about how can clearly emphasize that this class is private. Do you know if such a method exist at all? If yes I'll be grateful you give me some link here or something?

Just to keep things clear, a sample code:

public class DataStrucure {
     // fields, methods, etc
     private class InnerOddIterator{
          // ... 
     };
}
like image 457
guitar_freak Avatar asked Nov 26 '14 10:11

guitar_freak


People also ask

Can a nested class be private in Java?

Static nested classes do not have access to other members of the enclosing class. As a member of the OuterClass , a nested class can be declared private , public , protected , or package private. (Recall that outer classes can only be declared public or package private.)

How do you represent nested classes in UML?

Per UML 1.4. 2 a declaring (nesting) class and a nested class could be shown connected by a line, with an "anchor" icon on the end connected to the declaring class. An anchor icon is a cross inside a circle.

How do you represent private in UML?

The UML represents instance variables as attributes by listing the attribute name, followed by a colon and the attribute type. To indicate that an attribute is private, a class diagram would list the private visibility symbol—a minus sign (–)—before the attribute's name.

Do UML diagrams show private functions?

In general UML provides a mechanism to show operation (and attribute alike) visibility. As private feature can be depicted on a diagram it is clear that you can present it on a diagram. However if you show it or not depends what you're modelling. If you're modelling the internal behaviour of the class then yes.


3 Answers

From UML point of view. If classifier (Class also) is nested in other class, nesting class plays role of namespace. In this case nested classes are hidden (private) in context namespace. it means, your diagram implicitly defines private inner class definition.

here is part of definition from UML Superstructure section structred classifiers:

"A class acts as the namespace for various kinds of classifiers defined within its scope, including classes. Nesting of classifiers limits the visibility of the classifier to within the scope of the namespace of the containing class and is used for reasons of information hiding. Nested classifiers are used like any other classifier in the containing class."

like image 165
Vladimir Avatar answered Oct 07 '22 06:10

Vladimir


First of all: You have something in your code and asking for an UML representation. But, IMHO, you should look at it the other way round: How can that UML-idea be represented in code. (Some programming languages don't even offer private nested classes...).

As for private nested classes: I suggest using a Composition. It is stronger as Association but not as strong as inheritance. And the composed class can not exist without its composer. Pretty much exactly a private nested class.

The drawing is taken from http://www.uml-diagrams.org/association.html: enter image description here

like image 20
Martin Meeser Avatar answered Oct 07 '22 06:10

Martin Meeser


In order to indicate that your inner class is privete the best, for me, is to use - character as depicted below but of course in this case you miss the internal structure of your inner class..enter image description here

like image 2
Red Beard Avatar answered Oct 07 '22 06:10

Red Beard