Book a Demo

Author Topic: c# generics  (Read 5354 times)

Mr. Sanders

  • EA User
  • **
  • Posts: 187
  • Karma: +0/-0
  • Dilbert for president
    • View Profile
c# generics
« on: November 26, 2007, 07:42:18 am »
Hi,

I already read some threads about generics and problems with EA, but I can't find a solution, just problem descriptions.

I want to model an agregation from class A to

class MyGenericClass<MyConcreteClass> in a way that it resulst in

class A
{
...
private
 MyGenericClass<MyConcreteClass> myInstantiatedGeneric;
...
}

Is there a way to model it and to generate that code?

I do not want to model it as an attribute!
Thats what I have done now as a workaroud.

I want to model an aggregation relationship.

Regards
Michael




Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: c# generics
« Reply #1 on: November 26, 2007, 11:01:13 am »
Michael,

One of the problems you have is that in UML (unless something has recently happened to invalidate this) a named Association End IS an Attribute.  So what you want can be rendered both ways, as a UML Feature (Aggregative Attribute) OR Edge (Aggregative Association) OR both since they all mean the same thing.

Your problem is that EA makes them different.  We have previously asked for better coordination between the two renderings and Sparx have done some work to improving it, but then stopped.

Certainly, making them the same "thing" is still a long way off.

HTH,
Paolo
« Last Edit: November 26, 2007, 11:59:10 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: c# generics
« Reply #2 on: November 26, 2007, 11:19:53 am »
Or not...

Perhaps Michael can make a feature request to Sparx. That will help show that Paolo and I don't just represent an anomalous cluster of UML radicals, and that clearing up this area of EA has merit.

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: c# generics
« Reply #3 on: November 26, 2007, 11:39:36 am »
Look up collection classes in the help.

You'll need to set a collection class for C# (Tools | Options | C#) or MyConcreteClass (Class properties detail tab).

Then use a multiplicity along the lines of 0..* or 1..*.

Mr. Sanders

  • EA User
  • **
  • Posts: 187
  • Karma: +0/-0
  • Dilbert for president
    • View Profile
Re: c# generics
« Reply #4 on: November 26, 2007, 11:58:26 am »
Quote
Michael,

One of the problems you have is that in UML (unless something has recently happened to invalidate this), a named Association End IS an attribute.  So what you want can be rendered both ways, as a UML Feature (Aggregative Attribute) OR Edge (Aggregative Association) OR both since they all mean the same thing.

Your problem is that EA makes them different.  We have previously asked for better coordination between the two renderings and Sparx have done some work to improving it, but then stopped.

Certainly, making them the same "thing" is still a long way off.

HTH,
Paolo


Hello Paolo,

I would be satisfied if I could model just one of them.
And of course they are attributes at least in the code.
But I want to see this attribute as an aggregated class
in UML in EA.

May be I again wasn't able to explain what I want.

In rational rose I was able to drop an instantiated element of an template class. This instatiatian has conrete parameters for the templates elements.

And that' what I want to do with the generic class.
I have a generic (in c#, which is a template class in c++)

Now I want to drag an instantiated generic class and fill in the conrete classes for the template parameters, just as I would do it with a instantiated template class in C++ in rose.

The collection class option doesn't help, because this is a one time task.

The next aggregation modeled has different parameters.

What's the way to model it as an aggregation and not as an class attriubte. (I have done it as an class attribute, but this is a case where i want to exponate the special character of the member and therefore I want to use an UML aggregation.

And it should be generated as an class attribute in c# code.

Thanx for all answers until now.

Regards
Michael

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: c# generics
« Reply #5 on: November 26, 2007, 12:05:40 pm »
Hi Michael,

If I now understand you correctly, it is still the same problem!  If EA instantiates the generic correctly (and there are doubts about that) then if creates an Attribute of type 'X' then it should also show an Association to the Class 'X' (whether it's aggregated or not seems irrelevant to me).

Have I understood your issue more correctly now?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Mr. Sanders

  • EA User
  • **
  • Posts: 187
  • Karma: +0/-0
  • Dilbert for president
    • View Profile
Re: c# generics
« Reply #6 on: November 26, 2007, 12:39:04 pm »
Hello Paolo,

may be I don't understand you.

Thats what I have:

I have a class diagram.

In the class diagram I have class A
In the class diagram I have a generic class MyGeneric.

MyGeneric has at least one parameter class T1, which is unspecified. (Therefore it is an generic).


Now I want to model an aggregation in the class diagram
in a way that class A aggrates MyGeneric<MyConreteParameterClass>

What I am able to model is

A ---- aggregates ---> MyGeneric<T1>

which is wrong, becaus i need a concrete parameter class for T1.

But even if I generate this code, I get

class A
{private MyGeneric mzMember}

which is worse, because even the T1 is missing in code.

What do I have to model in the class diagram,
that I get

class A
{
 private MyGeneric<MyConcreteTemplate> myMember;
}

If I haven't understood you again.
Don't try to explain again.
I think I have to go outside and walk a couple of meters, that my brain will get some oxygene.

Thank you for your help.

Regards
Michael
« Last Edit: November 26, 2007, 11:35:31 pm by mizd »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: c# generics
« Reply #7 on: November 26, 2007, 03:14:48 pm »
Michael,

It was me that misunderstood.  This last explanation, I think, has clarified what you are trying to do.  I was talking about things from the point of view of the instantiation of the generic (that is from the instance looking outward).

If I NOW understand you correctly, you are after an inbound Association to the instantiated generic.  This looks much more problematic.  I'll have to go away and have a think.

In the meantime, others may be able to confirm my new understanding is what you intended all along and may be able to offer a solution.

Now awake (the previous post was during a sleepless night :))
Paolo
PS: I still think that whether the Association is an aggregation or not is not the main issue.
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Mr. Sanders

  • EA User
  • **
  • Posts: 187
  • Karma: +0/-0
  • Dilbert for president
    • View Profile
Re: c# generics
« Reply #8 on: November 26, 2007, 11:37:19 pm »
Hello Paolo,

yes that sounds better to me.

It seems that our brains have matched (at least a bit).

Michael