Sign up UML association vs. composition and detail level

UML 2016. 10. 13. 10:39
반응형

Actually, make that a couple of amateur UML questions! When creating a UML diagram to model some domain concepts and you come across a domain concept that "holds" some information about another concept, is it better to hold a stamp/reference to that entity or hold the whole entity in the model itself? Please bear in mind that this is relating to creating a simple high-level model - I'm sure in the implementation stage things would be slightly different.

For example, which of the two models below is actually correct? The first one has a composition relationship, with FlightBooking holding the whole of Flight. In the second one, FlightBooking just has a reference to Flight.

http://imageshack.us/m/96/2227/flightiu.png

Secondly, when creating a high level UML diagram modelling domain concepts, how much detail are you really meant to go? For example, in the diagram below, a flight could hold details about origin/destination as strings, or I could model separate classes for these concepts and create a composition relationship. Which of the two is advisable?

http://imageshack.us/m/23/3395/flight2s.png

Also, just another thing, when modelling the above where a Flight "holds" an orig/destination as another class rather than a string, which of the two ways is the correct way of modelling this? I'm quite confused as to when to show assosciation and when to show composition.


A

Association :
It means two classes have some kind of relationship, could be anything really.
E.g : A uses B, A is related to B in a given way.

Composition :
This is also a special type of association used for modelling 'Ownership'. This is very similar to Aggregation with the only difference that it depicts a Whole-part relationship and the 'part' entity doesn't have its own independent existence

E.g : A consists of B; B is a part of A and hence cannot exist without A.


http://javarevisited.blogspot.kr/2014/02/ifference-between-association-vs-composition-vs-aggregation.html



반응형
: