Change class of a given EObject [message #755126] |
Mon, 07 November 2011 08:25  |
Eclipse User |
|
|
|
Hi there,
is there any practical way to change the class of a given EObject to a
subclass of that object?
e.g. I have a class "Person" and subclasses "Man" and "Woman".
For some reason I have an instance "Foo" of "Person", yet not knowing
the gender. Later I get the information that "Foo" is male but my model
has no gender attribute but uses subclasses for the gender.
Is there a way to "upgrade" the class of Foo from Person to Man?
A workaround would be to create a new Man, copy all attributes and
replace it in the containment hierarchy of Foo. However, there might be
cross-references to Foo which I also would need to switch to the new Man
instance.
Is there a good way to find all foreign references to Foo so I can
switch them to the new instance?
Rationale: I encounter quite often MM that code information in
subclasses rather than in attributes. This is nice for using
polymorphism, but bad for changing the objects as discussed above.
Any hint how to handle that?
Cheers,
Hauke
|
|
|
|
|
Re: Change class of a given EObject [message #755179 is a reply to message #755126] |
Mon, 07 November 2011 10:38  |
Eclipse User |
|
|
|
Hauke,
Comments below.
On 07/11/2011 2:25 PM, Hauke Fuhrmann wrote:
> Hi there,
>
> is there any practical way to change the class of a given EObject to a
> subclass of that object?
No.
>
> e.g. I have a class "Person" and subclasses "Man" and "Woman".
>
> For some reason I have an instance "Foo" of "Person", yet not knowing
> the gender. Later I get the information that "Foo" is male but my
> model has no gender attribute but uses subclasses for the gender.
>
> Is there a way to "upgrade" the class of Foo from Person to Man?
No.
>
> A workaround would be to create a new Man, copy all attributes and
> replace it in the containment hierarchy of Foo. However, there might
> be cross-references to Foo which I also would need to switch to the
> new Man instance.
> Is there a good way to find all foreign references to Foo so I can
> switch them to the new instance?
EcoreUtil has UsageCrossReferencer. You could look at DeleteCommand to
see how it's used.
>
> Rationale: I encounter quite often MM that code information in
> subclasses rather than in attributes. This is nice for using
> polymorphism, but bad for changing the objects as discussed above.
>
> Any hint how to handle that?
>
> Cheers,
> Hauke
>
|
|
|
Powered by
FUDForum. Page generated in 0.10839 seconds