I know the basics but do not how to model this (it is an exercise with no solution provided):

An order can contain 1 or more cartons of beer. Each carton contains 6 beers of the same kind but there are some consisting of 3 different beer types (still 6 in total)

Also having a "Carton" class, how can I make it the way it either 6 beers (same ones) OR 6 beers of 3 various types?

1 Answer 1


You can use the xor contstraint to model exclusive or. If you really know the basics, you should have seen it already.

The rest is straightforward. You have an order class which has one or more cartons (1..*). You could model this association with an aggregation but it's not exactly specified. However, it's not a composition, as cartons can definately exist on their own.

There are multiple solutions for how to model the carton. The first that comes to my mind is to split the cartons into two types. One for single beer type, one for multiple beer types. Both derive from an abstract class using generalization. The order is associated only with the abstract carton class.

The thing with beer is, that you could also split it up into an abstract class and its derived beer types, but this is not really needed here. So you could just create three different beer classes. The first carton (single beer type) is associated with all three beer classes with the multiplicity 6 and constrained with xor constraints between the three associations. The other carton (three beer types) is also associated with all three beer types. However, you don't need the xor constraint and the multiplicity is 2 for each association.

There are definately more elegant ways to model this, but this one should at least be considered correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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