Default value of an inherited string attribute [message #418960] |
Mon, 05 May 2008 16:25  |
Eclipse User |
|
|
|
Hi all,
I'm new to EMF and I have a simple question about the default value of a
string attribute.
Suppose for example that I have the following classes:
1- MyClassA with a
- MyStringAttribute
2- MyClassB (its parent class is MyClassA)
3- MyClassC (its parent class is also MyClassA).
Now suppose that I need to have a different initial value for
MyStringAttribute depending on which classes I will instantiate.
A) MyStringAttribute must be "myStringA" when i create an instance of
MyClassA
B) MyStringAttribute must be "myStringB" when i create an instance of
MyClassB and
C) MyStringAttribute must be "myStringC" when i create an instance of
MyClassC and
Should I do this by modifying the generated code or is there a way to do
this using the emf user interface.
I looked for a way to redefine the attribute in the subclass and tell
EMF that this attribute is derived from the parent but it doesn't seem
to work.
Any idea?
Thanks
Vincent
|
|
|
|
|
Re: Default value of an inherited string attribute [message #418976 is a reply to message #418973] |
Tue, 06 May 2008 10:42  |
Eclipse User |
|
|
|
Vincent,
I'm not a big fan of redefinition for several reasons. Even your
examples below point out odd inconsistencies. I have a MyClassA
instance and I cannot change the myStringAttribute, only it turns out
that the instance isn't just a MyClassA, it's a MyClassB, which I
wouldn't know without an instanceof test, and hence I can actually set it.
If these are ways in which you want to constrain the behavior in the
editor or to initialize new instances created in the editor, it's much
better to do that in the item providers than to try to define things in
the metamodel where assumptions in a base class turn out to be wrong in
a derived class...
Vincent L. wrote:
> Hi.
>
> Thanks for your answer... but i'm not sure it will help me.
>
> My problem is more general than the default value problem. It applies
> to any setting of model element that we could want to override when
> you derive a class from another one.
>
> Suppose that I have the same classes (myClassA, myClassB, myClassC)
> with the same attribute myStringAttribute but now instead of a
> different default initial value, I want to have a different
> "changeable" setting
>
> 1- myStringAttribute is read-only in myClassA (changeable = false)
> 2- myStringAttribute is read-write in myClassB (changeable = true)
> 3- myStringAttribute is read-only in myClassC (changeable = false)
>
> I know that I can change the code of the ItemProvider of each subclass
> to make the attribute changeable or not but it could be boring to do
> this for all setting that I want to override in subclass...
>
> Any idea? Is my question well formulate?
>
> Thanks.
>
> Vincent
>
|
|
|
Powered by
FUDForum. Page generated in 0.24652 seconds