Home > database >  What does "age: Integer{0<=age<=150}" mean in UML Diagram?
What does "age: Integer{0<=age<=150}" mean in UML Diagram?

Time:12-03

I want to write a C# code from UML Diagram as shown below. However, I come across this attribute "age: Integer{0<=age<=150}". I will circle for you. May I know what it means? and How can we convert it to C# code? C#

CodePudding user response:

It means the minimum limit of age is 0 and maximum is 150. A person in the system should not have a negative age or an age more than 150 years.

You can implement this by having a condition to check the age value when a user enter it to the system.

CodePudding user response:

This is called a constraint and can be recognized by the surrounding curly brackets. You can write either clear text, use a mathematical formula or write OCL (not for the faint hearted and probably too lenghty in any case here).

See p. 35 of UML 2.5:

A Constraint is an assertion that indicates a restriction that must be satisfied by any valid realization of the model containing the Constraint. A Constraint is attached to a set of constrainedElements, and it represents additional semantic information about those Elements. [...]

<constraint> ::= ‘{‘ [ <name> ‘:’ ] <boolean-expression> ‘ }’

  • Related