Why cannot I connect an object (instance of a class) to a specific attribute of another object (instance of a class) in Enterprise Architect?

I have a question regarding linking of elements to attributes:

Question: Why cannot I connect an object (instance of a class) to a specific attribute of another object (instance of a class) in Enterprise Architect?

I do not see any constraints in UML that would not allow me to do that. This is what I tried:

  1. I know that I can link classes to a specific attribute of another class as shown in the following figure:

enter image description here

  1. The end result will then look like this where I have a Store class connecting via two attributes Manager and Deputy to a Person class:

enter image description here

  1. From there I can select the actual attribute to link to:

enter image description here

  1. I also marked the attributes containment as By Reference to indicate that the value of the attributes should not be a scalar or simple value (shown as an asterisk next to the attribute):

enter image description here

  1. But as soon as I create instances of the classes I cannot unambiguously connect the Person to the respective attributes of the Store instance:

enter image description here

  1. This is because the Link to Element Feature does not allow me to select an attribute. Even, when I add an additional attribute to the Store1 instance (test in my example) I cannot select that attribute from the list of attributes. So it is not clear, which of the two Person instances is actually the Manager and the Deputy.

enter image description here

Is there any explanation why this is not possible? Is this a bug? How are others trying to modell such a relationship?

Thanks for your advice! Regards, Ronald

Upvotes: 3

Views: 941

Answers (3)

Instead of tying the connectors to actual Attribute of the instance (that have to be created manually as outlined in the other answer) we can also use an annotated connector where the the text of the connector by convention denotes its intended usage as shown in the following figure:

Object instance with connections to two different instances of the same type with annotated connectors

This has some advantates over the other solution:

  1. No need for coding - everything can be done from via the UI
  2. No need for custom sparx features (Link to Element Feature) - everything can be modeled via plain UML

One downside is similar to the other solution: in case the class name changes the connector annotation has to be updated as well. On the other hand, changing the name of the class is in my opinion less likely than changing an attribute name. Another disadvantage is that the whole mechanism depends on convention (class.attribute).

For me this works best as it is visually clear and the fastest way to implement.

Upvotes: 3

Based on the clue of @Thomas I realised that I could redefine the attributes on the object instance in order to be able to connect them to another object instance.

With the script lines below I now can easily recreate the all attributes on the object instance:

$objectId = '{F4DB0F04-18D4-4acb-BA1D-FF55813D7559}'

$object = $ea.GetElementByGuid($objectId);

$classifier = $ea.GetElementById($object.ClassifierID);

$attrsByRef = $classifier.Attributes |? Containment -eq 'By Reference'

$attrsByRef | Select Name, AttributeGuid

Name    AttributeGUID                         
----    -------------                         
Manager {614E5483-2E06-4070-AFB7-B4EDB4A981A7}
Deputy  {82403A08-5E2A-4e68-B39A-6220C889C6E9}

foreach($attr in $attrsByRef) 
{ 
    $objattr = $object.Attributes.AddNew($attr.Name, $attr.Type); 
    $objattr.ClassifierID = $attr.ClassifierID; 
    $objattr.Update(); 
}

I can then use the standard link to element feature from the UI or via StyleEx from the API to connect the Person instances with the correct attribute:

Object with Attributes

In the project browser I can now see the attributes under the object:

Project Browser View

This is certainly not an ideal solution, but in my opinion still better that to use associations to model each single attribute.

Upvotes: 1

qwerty_so
qwerty_so

Reputation: 36295

Very simple: An instance does not have attributes. None at all. You can show values for instantiated attributes, but that's not the same. For that simple reason you can not link connectors.

Linking to features is a Sparx feature and not UML standard. You might send a feature (huh, so many features here) request to Sparx to support what you wish.

Anyhow, you can use Pin End(s) from the context menu. This will fix one (or both) end(s) of the connector ends to where you want it.

Upvotes: 0

Related Questions