UML association vs. composition and detail level

前端 未结 4 1537
北荒
北荒 2020-12-04 20:21

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 inf

4条回答
  •  离开以前
    2020-12-04 20:58

    Compositions, aggregations and associations.

    • Before other things you should understand what the association A to B is.
      • Basically it is a solid line between A and B. It can represent one structure that connects class/instanc(es) of A with the class/instances of B. The structure can be of any sort and belong anywhere. All information, written about the line, describes this structure.
      • If there are two structures, one structure, that connects one instance of A with instance(s) of B and another structure that connects instance of B with instance(s) of A, you can show them both in ONE association. Then, information written about its B end describes the first structure (b->a) and info about the other end describes the other structure.
      • If you'll have more than one structure guiding from A to B, you have to draw two different associations.
      • If a joining structure is complex, you could represent it as an Association Class. There you can define more details.
      • A joining structure can connect more than two classes, then it will be shown as a large diamond with solid branches to these classes. It is still association! Attention: these two more complex associations are very badly supported by existing tools. You can easily create something absolutely senseless with them. And they are difficult. Use carefully.
    • In C++ instance A can have the B instance not by pointer, but directly. There is NO special UML sign for it, it should be shown in the same way as normal, pointer attribute.

    example Class diagram


    • Composition is shown by what is called black or full diamond. It is on the side of the container.
    • The other one, empty diamond, is called "shared aggregation", or, shortly, "shared". It is not strictly defined and you can use it creating your own standard. Of course, it would be foolish to put it on the item side of item-container association. But it easily could be on the both ends of association.
      • Why the composition diamond can be only on one side? Because composition means, that items exist ONLY while exist reference to them from the container (or container itself). Of course, that couldn't work for both sides.
      • On the contrary 'shared' on both sides often has sense. For example, Student instances can have a list of all courses attended, and Courses instance can have a list of all students attending.
    • Often you can see name "aggregation" used for "shared aggregation". It is a BAD mistake. Because, according to standard, composition, shared and even none, all three are aggregations.

    So, composition is a subset of aggregation and aggregation is a feature of the association

提交回复
热议问题