Simple UML behaviours baffle me!

229 views Asked by At

Very new to UML and system design.

We're at the stage of doing a class diagram in the design phase and are struggling to figure out how to implement a requirement. Here's the problem:

We have a Person class that is composed of a Name class and a ContactDetails class. Contact details class is composed of a MobileNumber and an EmailAddress class.

How would I model my class diagram so that ContactDetails must have either MobileNumber or EmailAddress or both?

I'm sure it's simple - but it's thrown me!

Thanks

2

There are 2 answers

3
rdmueller On

let's start simple:

Model your classes as you would write your program. Create a ContactDetails class and add two attributes "MobileNumber" and "EmailAddress", both of the corresponding type. Now create your constructor methods:

+ContactDetails(mn MobileNumber)
+ContactDetails(email EmailAddress)
+ContactDetails(mn MobileNumber, email EmailAddress)

Now: how would you add the needed constraint in code?

By setting the empty constructor as private? Do so!

-ContactDetails()

By checking that the parameters are not empty? Just add a Constraint element which basically just a text note to your class.

That's it.

1
Doug Knesek On

alt text

Also, if an association is optional, it is not a composition. It is at most an aggregation, or even a simple association as I show in this diagram.