1

If you have multiple instances of a classifier with the same name, do they simply combine, or is that not allowed?

For example, are these two equivalent?

+-----+ +-----+       +-----+
| Bar | | Bar |       | Bar |
+-----+ +-----+  vs.  +-----+
| +a  | | +b  |       | +a  |
+-----+ +-----+       | +b  |
                      +-----+

The reason for breaking a classifier down would be for reasons of laying out a readable diagram.

Are there any standardized ways of defining a classifier (e.g. a class) piece-wise?

  • 1
    I have a related question, which I'll throw in as a comment. Does UML have a notation for extension methods? – Nick Alexeev Oct 15 '15 at 19:07
  • @NickAlexeev UML class diagrams are about illustrating the relationships between objects. Strictly speaking, extension methods have nothing to do with OOP – they're just syntactic sugar for static functions, and these methods are not part of the object. However, it might still be helpful to list them as ordinary methods when this makes the diagram less confusing, perhaps with an «extension» stereotype. – amon Oct 15 '15 at 20:06
3

In the end, UML is a visual language to communicate a design between humans. So while you have a lot of freedom to communicate the same information differently, you should try to choose the clearest way. If you show me an UML class diagram where two classes have the same name, I would presume this to be a mistake. It is not a good idea to represent the same class multiple times in the same diagram. Therefore, if a class is used in two contexts in the same diagram, you should only draw the class a single time.

However, it might be reasonable to draw multiple diagrams to emphasize different aspects of your architecture. In that case, you can leave out any attributes of your classes that are not relevant in this context. E.g. if the existence of a member a adds no information to a diagram, leave it out. A class diagram does not have to communicate the whole design at once.

  • My question is about standard UML. UML might be for human consumption, but at a basic level it is a completely formal standard, and - visual or not - is supposed to have a formal representation with certain semantics. I want to know what the standard says, because it'd otherwise take days for me to trudge through enough of it to get an idea... – Kuba Ober Oct 15 '15 at 20:51
  • @KubaOber I am not aware that the UML standard allows the same concept in your model to be defined multiple times inside the same diagram. Since one diagram element corresponds to one model element, the standard suggests but does not specify that having two separate classes in the same diagram that are both labelled with Bar would be different classes. – amon Oct 15 '15 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.