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?
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.
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.
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.
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.
You can represent them externally with a containment
having a +
sign on the side of the outer class. You can find it here.
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.
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