constraintsumlinstanceclass-diagrammultiplicity

How to specify number of instances in UML Class diagram


Is there a way in a UML class diagram to indicate how many instances of a given class will be present in your system?

I know you can indicate the multiplicity of a relationship between classes:

Dog * ----------- 1 Yard 1 ----------- * Tree

But is there a common way to visually depict that there is exactly say, five instances of Yard in the model?


Solution

  • You cannot express this directly with UML bit with OCL (Object Constraint Language). It would be an invariant of Yard like

    context Yard inv: Yard.allInstances()->size()=5
    

    OCL is a language designed to express formal constraints when modelling with UML.