Book a Demo

Author Topic: How to create arrays of attributes?  (Read 9556 times)

Andris

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
How to create arrays of attributes?
« on: July 06, 2008, 09:04:53 am »
Hi,

I tried to create an array of doubles in a class diagram, so I added a new attribute, selected a type of double and looked for any switch to turn it to an array. In the Detail tab I found a Multiplicity section and I set it to some value (though I wanted to have an unspecified array). After that in the class diagram the attribute looked like this:
-test: double[20]
I generated C# code and I get this:
private double test;
That is not what I expected. I hope there is a solution to create an array type other than adding to data types one by one the related arrayed type. Any idea?

Till

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: How to create arrays of attributes?
« Reply #1 on: July 06, 2008, 08:31:08 pm »
Hello,

yes, there is a way of doing this. Open the properties of the corresponding attribute and go to the "Detail" tab. Tick the box "Attribute is a Collection" and put "[]" into the "Container Type" field, then click "Save" at the bottom.

Hope this helps.

Cheers,

Till

P.S.: Note that it is probably better to use a "real" collection type here as you can manipulate its content more dynamically than you could with an array. You could then still use a getter or property to return an array to the caller.

Andris

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: How to create arrays of attributes?
« Reply #2 on: July 06, 2008, 09:10:22 pm »
You mean I should use List? My next question is about that, anyway. How can I create a List<MyClass> or List<int> generic type attribute? If I add List<MyClass> to container type, I get this: private double List<MyClass> test. So is there a way to create generic types other than adding them to data types?

Till

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: How to create arrays of attributes?
« Reply #3 on: July 07, 2008, 02:13:13 am »
Hi,

whether you use a generic list really depends on your modelling approach. If you prefer to create a technical class model, you would use "List<double>" directly as a type for your attribute (without explicitly declaring the attribute a collection). You do not need to extend the data types of the programming language for this purpose since they should only contain primitive list types.
This of course results in a tight coupling between your model and the future implementation (C#, Java, etc.) since you use language-specific data types.

The other approach is to create a business domain model first. In this case you would model multi-valued dependencies by an association. You can then specify default collection types which are to be used for the implementation of such associations in the EA Options or in the properties of the association itself.

You kind of have a point there since you want to specify an attribute containing a set of "double" values, i.e. a set of primitive data type instances. In case you are developing a domain model, I would probably stick with an array. With regard to more complex data types, e.g. collections of user type instances, I would only use associations to model multi-valued dependencies.

Cheers,

Till

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to create arrays of attributes?
« Reply #4 on: July 07, 2008, 05:39:46 am »
Till,

EA seems to model generics using the same constructs as C++ (for example) parameterized classes. Though the two concepts are not isometric, neither language (or set thereof) to uses both, and EA seems to make it work well enough.

David
No, you can't have it!