Book a Demo

Author Topic: How can I instantiate an aggregation?  (Read 6220 times)

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
How can I instantiate an aggregation?
« on: March 09, 2009, 03:48:50 pm »
Hi All,

I am struggling with what seems like a simple problem.
I have defined two classes such that one class contains an array of the other:

dog <>-------leg

and the relationship is established by a "aggregation" (solid diamond).

In a separate diagram, I make instances Rex:dog, Shep:dog and RexLeg:leg. What is the EA mechanism to associate the instances according to the already-defined aggregation relationship? RexLeg is a part of Rex, but not a part of Shep. Right now my instance diagram shows Rex, Shep, RexLeg all unconnected.

I tried, in the instance diagram, to right-click on Rex:dog then Add | Related elements..., but that did not work. I tried drawing a new aggregation on the instance diagram, but that seemed to be a new relationship. I tried hunting in the project browser for the aggregation object so that I could drag it into the instance diagram, but aggregation relationships are not recorded in the project browser.

Another instance question, if I may. If the class has member int NumLegs, what is the proper way (in EA) to specify, for a specific class instance (such as Rex), that Rex.NumLegs = 4?  One solution is to add a constraint to the instance "NumLegs == 4", but its unclear that EA is recognizing the use of the member names in the contraint dialog (it seems that I could write just about anything into a "constraint").

Thanks for any input on these issues.

Regards,

Owen

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #1 on: March 09, 2009, 06:54:43 pm »
As to Rex.NumLegs = 4, you can set it as run state via the "Advanced - Set Run State" context menu for the  instance in the diagram.

Unfortunalety the run state only supports attributes, but not associations. I know of no way to link an association of instances to an association of classes.

I'd be glad to hear otherwise though.

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #2 on: March 10, 2009, 01:19:20 am »
Thanks Frank. Runstate is exactly what I needed.

A follow-on question.

I have a template class (C++) dataColumn (called a parameterized class in EA) and it takes a single template parameter: e.g. dataColumn<int> or dataColumn<double>.

When I make an instance of that class, where can I store the value of the template parameter?

Also, when I made the parametric class, I did get the dotted box on the class diagram. But I did not get the angle brackets in the classname. How do I get the class name to appear with angle brackets (e.g. as dataColumn<myTemplateParameter>).

As for my original question, I wonder if "make composite" is the solution. Experimenting, it seems possible to make an instance composite, then you can drag other instances onto the composition diagram. But again this seems too free-form. I could drag anything in there, not just the classes that are specified by existing aggregation relationships.

Regards,

Owen

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #3 on: March 10, 2009, 03:31:19 am »
Hi Owen,

The template parameters to use with an instance can be specified in the Details tab of the class element (Templates->Arguments field).
Regarding the <> C++ syntax, you may simply use the <> in your instantiated template classes names. Derive them from the template class using a generalization, implement all operations, and specialize them according the used template parameters. The instantiated template classes should not generate code (choose language <none>), this is done by the C++ compiler. You may need to correct the generated #include statements for the template class references.
If you don't need to model the dataColumn template class, but use it from a framework, it's enough just to use e.g. dataColumn<int> as Type for an operation parameter or attribute, to get correctly generated code (#include must be inserted manually in this case).

HTH
Günther
« Last Edit: March 10, 2009, 03:33:30 am by Makulik »

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #4 on: March 10, 2009, 07:25:15 am »
Thank you Günther.

Quote
The template parameters to use with an instance can be specified in the Details tab of the class element (Templates->Arguments field).

I do not fully understand. It seems the template menu described above is available for the EA class definition, but not for the EA class instance. I did notice, at the Template dialog of the class definition that the "Arguments" field is only writeable if Type = "instantiated" (or "both") is selected. What should I put in that argument field, and where is it passing an argument from or to?

In my example I have a class dataColumn that has the following settings in the Template dialog

 Parameter colType
 Type         class
 Default      int

In another diagram, I have two instances of dataColumn

  dc1 : dataColumn
  dc2 : dataColumn

How can I set the colType of dc1 to float?  That is, how to specify that colType == float for instance dc1.  I guess it may relate to the Arguments field discussed earlier, but I'm struggling to see it.

Thank you for your patience.

Regards,

Owen

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #5 on: March 10, 2009, 07:43:44 am »
We seem to have two threads interleaved here ;) , serves me right for trying to put in an "extra" question. ha ha

On the original question, I think I see an answer.
In class dog, due to the aggregation, there must be a field something like "dog.leg_m leg[4]" . The RexLeg instance of leg can be associated to the Rex instance of dog by setting

RexLeg | general | role
       

to

Rex.leg_m[0]

. I have not looked at the code generated by this approach, but the resulting class appearance solves my problem: the role text appears as part of the instance class name (in bold at the top line of the class icon).

Regards,

Owen

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #6 on: March 10, 2009, 10:37:14 pm »
Quote

I do not fully understand. It seems the template menu described above is available for the EA class definition, but not for the EA class instance.
The instantiation of a parameterized class yields a class, from that point of view this is correct.

Quote
I did notice, at the Template dialog of the class definition that the "Arguments" field is only writeable if Type = "instantiated" (or "both") is selected. What should I put in that argument field, and where is it passing an argument from or to?
I think the Type should be "instantiated" in case of modelling a template class instantiation, the Arguments field should contain a (comma separated) list of classes/types corresponding to the specified class parameters.

If you want to see the instantiations of dataColumn for particular types, you need to model them explicitely as I described, and use them as type for your referencing classes' attributes. If you follow my proposal, the instantiated template classes will be named dataColumn<float>, dataColumn<int>, aso., so you'll clearly see what's actually used.
BTW the class parameter type of dataColumn should rather be 'typename' instead of 'class' to allow primitives passed as parameter.

This is all a bit tedious I know, and I remember that using a dependency connector with stereotype «bind» and the class parameters assigned to it from instantiated to parameterized class should do the same job. But it doesn't in EA and may be this was just Visio style to do it, dunno what the UML2.1 spec tells about this topic.

HTH
Günther

« Last Edit: March 10, 2009, 10:41:30 pm by Makulik »

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #7 on: March 11, 2009, 02:11:45 am »
Thank you Günther.

I made the subclass definitions as you suggested and I have been able to make a diagram that makes sense. After making subclass dataColumn<s8>, I can make an instance of dataColumn<s8>.

My parameter is now defined
  Parameter colType
  Type         typename
  Default      s16
  Arguments s8, s16, s32

How/where are the Arguments values used?  It did not seem necessary to my workflow.

Thank you again,

Owen


Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: How can I instantiate an aggregation?
« Reply #8 on: March 11, 2009, 05:25:21 am »
Hi Owen,

I think the Arguments list is only used, when code is generated for the parameterized class. But I'am not 100% sure about that ...

WBR
Günther