Override eSet()... Should I? [message #885782] |
Wed, 13 June 2012 15:28 |
Poissy B. Messages: 31 Registered: June 2012 |
Member |
|
|
Hi all EMFers!
Please bare with me since I'm new at EMF. I have a class that maintains two distinct collections of another class (1-many containment relationship). Here's a simplified example:
Class A{
EList<B> list1;
Elist<b> list2;
}
Class B{
}
My problem is that I would like to know, for a given instance of B, whether it belongs to list1 or list2 in the container instance A.
Of course, i could simply iterate through list1 and check if my instance of B is part of it. Since it could only be either part of list1 or list2, if it's not present in list1 i can deduce that it's part of list2.
However, this solution seems to be the least effective choice. So I thought having a boolean attribute isInList1 in B that gets set when I add an instance of B to an instance of A.
Going through the generated code, the only place I found to be able to do this is in eSet() (in the switch statement). Am I right?
If so, should I override the eSet method (@generated NOT)? I am worrying that if my model evolves and I change class A, say adding a couple of attributes, EMF won't generate the new eSet() and I could end up with hard to find bugs.
Do you guys could give me any advice on how to do this properly?
Thanks a lot!
Anis
[Updated on: Wed, 13 June 2012 15:30] Report message to a moderator
|
|
|
Re: Override eSet()... Should I? [message #885787 is a reply to message #885782] |
Wed, 13 June 2012 15:35 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Anis,
Comments below.
On 13/06/2012 5:28 PM, Anis B. wrote:
> Hi all EMFers!
>
> Please bare with me since I'm new at EMF. I have a class that
> maintains two distinct collections of another class (1-many
> containment relationship). Here's a simplified example:
>
>
> Class A{
> EList<B> list1;
> Elist<b> list2;
> }
> Class B{
> }
>
>
> My problem is that I would like to know, for a given instance of B,
> whether it belongs to list1 or list2 in the container instance A.
These are containment lists I guess. EObject.eContainmentFeature will
return whether it belongs to the feature for list 1 or 2.
> Of course, i could simply iterate through list1 and check if my
> instance of B is part of it. Since it could only be either part of
> list1 or list2, if it's not present in list1 i can deduce that it's
> part of list2.
> However, this solution seems to be the least effective choice. So I
> thought having a boolean attribute isInList1 in B that gets set when I
> add an instance of B to an instance of A.
> Going through the generated code, the only place I found to be able to
> do this is in eSet() (in the switch statement). Am I right?
No, lists have all their own internal methods; after all, you can add
directly to the list.
>
> If so, should I override the eSet method (@generated NOT)? I am
> worrying that if my model evolves and I change class A, say adding a
> couple of attributes, EMF won't generate the new eSet() and I could
> end up with hard to find bugs.
Yes, not generally a good idea.
> Do you guys could give me any advice on how to do this properly?
I think EObject.eContainmentFeature should be sufficient.
> Thanks a lot!
>
> Poissy
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03779 seconds