Reputation: 1289
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:
Store
class connecting via two attributes Manager
and Deputy
to a Person
class: 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):Person
to the respective attributes of the Store
instance: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
.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
Reputation: 1289
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:
This has some advantates over the other solution:
Link to Element Feature
) - everything can be modeled via plain UMLOne 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
Reputation: 1289
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:
In the project browser I can now see the attributes under the object:
This is certainly not an ideal solution, but in my opinion still better that to use associations to model each single attribute.
Upvotes: 1
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