Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private classes and uml

Tags:

java

uml

I have some inner private classes and I am unsure where to put them in my class diagrams. Should they be in their external classes or on their own?

like image 927
mr2k Avatar asked Apr 19 '12 10:04

mr2k


People also ask

How do you represent private classes in UML?

To indicate that an attribute is private, a class diagram would list the private visibility symbol—a minus sign (–)—before the attribute's name. For example, the instance variable course-Name in Fig. 4.7 would be modeled as "- courseName : string" to indicate that it's a private attribute of type string.

Is private or public in UML?

Public − A public member is visible from anywhere in the system. In class diagram, it is prefixed by the symbol '+'. Private − A private member is visible only from within the class. It cannot be accessed from outside the class.

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.

Is class and UML diagram same?

The main difference between UML and class diagram is that the UML is a general-purpose visual modeling language that helps to visualize, construct and document software systems while class diagram is a type of UML diagram that represents the static view of an application.


2 Answers

You can represent them externally with a containment having a + sign on the side of the outer class. You can find it here.

like image 138
Sunmit Girme Avatar answered Sep 25 '22 03:09

Sunmit Girme


There's always a difference between UML the language and whatever modelling tool you're using, so which is the best way of achieving something depends on the tool.

In UML, classes have a visibility/scope, just like class members do. In other words, UML allows for private classes, but that doesn't mean your tool can display the "privateness" of the class.

UML also allows classes to contain other classes. I other words, classes can act as packages. Again, how the tool displays this varies.

From a pure UML perspective, I would recommend having the inner class contained inside the outer, and marked private.

In a diagram, if your tool doesn't show the namespace, you could resize the outer class and place the inner inside it. If your tool allows resizing, that is.

Finally, unless you only have eight or ten classes in total, I would recommend showing the inner classes in a separate diagram.

like image 31
Uffe Avatar answered Sep 24 '22 03:09

Uffe