Setting the association end ownership in UML: What does it mean with respect to generated code in visual paradigm (or in other UML tools)?

后端 未结 3 863
情深已故
情深已故 2021-01-14 19:05

What is the effect of setting the association end ownership from \"association\" to \"classifier\" on the code that gets generated?

In other words,

0) I star

相关标签:
3条回答
  • 2021-01-14 19:28

    Ownership means that class or its instance has not only reachable way to instance of another class, but has it as an attribute (direct reference or simply contains it). Ownership does NOT belong to strict features of UML.

    • 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.

    example Class diagram


    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.

    0 讨论(0)
  • 2021-01-14 19:29

    I think the convention you are trying to deal with is now deprecated.

    Navigability notation was often used in the past according to an informal convention, whereby non-navigable ends were assumed to be owned by the association whereas navigable ends were assumed to be owned by the classifier at the opposite end. This convention is now deprecated.

    Source: www.site.uottawa.ca

    0 讨论(0)
  • 2021-01-14 19:31

    I could give you a general approach about how a general UML 2 source code generator might work (UML spec doesn't specify how to generate code from UML models)

    From my point of view, if the association ends (property) belongs to the UML class, then a field should be generated in the source code class, whereas if it belongs to the association no field is generated (allows you to model unidirectional or bidirectional associations between classes). Have a look to the example I've recently posted

    0 讨论(0)
提交回复
热议问题