Suppose I have 3 UML Class diagrams. One is University, other is College, the other is Department. Each University can have multiple colleges, each college multiple departments. I have the UML class diagrams for these, where I assume there is a association relationship between University and college, and between college and department.

Could you please help with these questions:

  • Is association the correct type of relationship, or should it be aggregation or perhaps composition?

  • Is there a methodology to change UML class diagrams such as above to Java code?

  • You have 3 classes in 1 diagram, and not 3 diagrams with 1 class in each, isn't it ?
    – Christophe
    Jan 27, 2019 at 11:04

2 Answers 2


Association can be correct, because aggregation or composition are special kind of associations.

Aggregation would be better (i.e. more precise), because it expresses a whole-part relationship. Here, Colleges are a definitively parts of the whole University, and Departments are parts of a whole College.

Composition is similar to aggregation, but with an exclusive ownership of the parts by the whole. So it's also a candidate here. However composition would mean that a College would exist only as part of a specific University; so when the University gets removed, so does the College. But this semantic would not correspond to the academic reality. The reality is that occasionally a department moves from one college to the other, or that universities in the same town get merged, but the underlying colleges still remain unchanged except for their logo. With composition, this would require to clone a College into the new University and destroy the original one (so after the operation, you'll have a new college), whereas with aggregation a simple reassignment would be sufficient. So aggregation is the way to go.

Now there are tools like BoUML, and lots of other tools (just google for UML class diagram generate java code) that transform an UML diagram in Java. But if you're learning, and for this specific example, it's also easily done manually (see for example this tutorial).


Association is very loose connection so it is not there in your example.

The relationship between university, college and department can be composition because if university gets destroyed, all of its colleges and departments get destroyed too. A department by itself has no meaning if it's not part of the university.

The student relationship is association because it is an independent entity who exist without the university. If the university or department get destroyed, student still exist.

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.