UML Notation - Aggregations/Compositions vs “Vanilla” Associations

前端 未结 5 1279
时光说笑
时光说笑 2020-12-15 12:54

I\'ve recently spent a good deal of time performing detailed UML designs of various SW components that I have since written. Looking back on what I have recently finished an

5条回答
  •  [愿得一人]
    2020-12-15 13:34

    Vanilla Associations, Aggregration and Compositions are sometimes explained with the following semantics:

    • vanilla association: one object 'knows' one ore more other objects
    • aggregation: one objects 'has' one ore more other objects
    • composition: one object 'consists of' one or more other objects - the subobject can not be without the composing container

    mostly differentation of aggregation and composition go around the question "if the master object is gone - what happens to the part objects?".

    So the idea is to have some integrity constraint like "on delete cascade" be described using a differentiation in using one of the three options. UML has three different symbols for this

    • no symbol - vanilla association
    • diamond - aggregation
    • filled diamond - composition

    The issue with these three options is that the semantics are not precise enough for real life situations, especially if you look at situations that change over time

    E.g. Trying to answer the simple question "How many tire-wheels does my car have?" Will lead to different answers:

    • 4 wheels which are permantly attached to my car
    • 1 spare wheel which I might use in an emergency
    • 4 wheels that are either my summer or my winter wheels and are not attached to the car in the other seasons

    How many of these wheels will be gone when the car is gone? If you try to model this situation with the three symbols UML is offering you'll end up with a lot of discussion and negotiation what your model really means. I think it is far better never to use aggegation and composition symbols but instead always describe the association semantics as precisely as possible with a few lines of text. This way you can make it clear to the people reading your model what you really want. I think it is even o.k. to write "A car is a composition of parts which includes the wheels ...."

    But now you are not using a composition symbol but are really referencing the act of composing something.

    see also http://de.wikipedia.org/wiki/Assoziation_%28UML%29#Aggregation_und_Komposition (german)

提交回复
热议问题