Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Default value of an inherited string attribute
Default value of an inherited string attribute [message #418960] Mon, 05 May 2008 20:25 Go to next message
VincentL is currently offline VincentLFriend
Messages: 88
Registered: July 2009
Member
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 #418962 is a reply to message #418960] Mon, 05 May 2008 20:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Vincent,

Comments below.

Vincent L. wrote:
> 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.
EMF doesn't support that.
>
> 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.
Are you sure you really need such defaults right in the model. Perhaps
specializing the item providers to set such values when new instances
are created would be better.
>
> 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.
Nope. EMF doesn't support redefinition.
>
> Any idea?
It's best to avoid doing this in the model if possible. If you didn't
do this in the model, what would not work well?
>
> Thanks
>
> Vincent
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Default value of an inherited string attribute [message #418973 is a reply to message #418962] Tue, 06 May 2008 14:11 Go to previous messageGo to next message
VincentL is currently offline VincentLFriend
Messages: 88
Registered: July 2009
Member
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
Re: Default value of an inherited string attribute [message #418976 is a reply to message #418973] Tue, 06 May 2008 14:42 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
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
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:ChangeDesciption issue
Next Topic:How to hide attribute in property view
Goto Forum:
  


Current Time: Fri Apr 26 02:41:49 GMT 2024

Powered by FUDForum. Page generated in 0.03000 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top