Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Setting an Enum Reference Value in the Subclasses(Setting an Enum Reference Value in the Subclasses)
Setting an Enum Reference Value in the Subclasses [message #1742653] Tue, 06 September 2016 11:43 Go to next message
Bugra M. Yildiz is currently offline Bugra M. YildizFriend
Messages: 106
Registered: July 2014
Senior Member
Hello,

I have a metamodel in ECore. In this metamodel, I have an enum declaration, say

tag_enum = {SC_A_tag = 1, SC_B_tag = 2 }.


And I have a parent EClass, PC_E; and two subclasses of it, SC_A and SC_B.

PC_E has an attribute tag of type tag_enum. This attribute needs o be set in the subclasses: All instances of SC_A, the value of tag is SC_A_tag (an a similar case goes for SC_B). Is there was way to fix this in the metamodel instead of pushing this to OCL or model instantiation?

Thanks.


Re: Setting an Enum Reference Value in the Subclasses [message #1742658 is a reply to message #1742653] Tue, 06 September 2016 12:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31900
Registered: July 2009
Senior Member
I suppose you're using OCL in Ecore in which case it's better to ask on the OCL forum. In general I imagine PC_E is abstract and tag should be derived feature for which the implementation classes of the SC_A and SC_B should specialize the getter to return the appropriate enumerator. I'm not sure how you'd specify that with OCL in Ecore...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Setting an Enum Reference Value in the Subclasses [message #1742659 is a reply to message #1742653] Tue, 06 September 2016 12:59 Go to previous messageGo to next message
Erick Hagstrom is currently offline Erick HagstromFriend
Messages: 108
Registered: April 2014
Location: USA
Senior Member
I hate when people say things like this, but ...

this smells like an X/Y problem (http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Since all instances of SC_A are already easily differentiable from all instances of SC_B, you should be able to accomplish anything you want that's subclass-specific without assigning an enum.

What are you really trying to do?
Re: Setting an Enum Reference Value in the Subclasses [message #1742662 is a reply to message #1742659] Tue, 06 September 2016 13:09 Go to previous messageGo to next message
Bugra M. Yildiz is currently offline Bugra M. YildizFriend
Messages: 106
Registered: July 2014
Senior Member
1. Ed, actually I am trying to avoid OCL for doing this check. Instead of using operations like getters and setters, I prefer to set the attribute directly since the metamodel will be used as a data structure rather than having some dynamics like operations.

2. I see what you mean Erick and I agree with your point with the current setting of the question. Maybe, I should make it clear, these enum values are going to be processed later in some other setting. So, they don't actually serve the purpose of distinguishing the subclasses, rather keeping a constant data. If I don't present this data inside the metamodel (this is my question: How to do it properly?), then I have two options: (a) Set the correct values each time I create an instance of the metamodel, (b) Since these values will be useful in the later processing step, I can embedded them to the processing step; which conflicts with separation-of-concerns principle.
Re: Setting an Enum Reference Value in the Subclasses [message #1742667 is a reply to message #1742662] Tue, 06 September 2016 13:38 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7161
Registered: July 2009
Senior Member
Hi

You are requesting a class-dependent behavior. Standard OO languages offer class-variance using virtual operations, but not virtual properties. If you really want a variant property you will need to define the property as derived from a virtual operation, which probably is exactly what you were trying to avoid.

Regards

Ed Willink
Previous Topic:[CDO] Cross model references
Next Topic:How to semantically group elements?
Goto Forum:
  


Current Time: Mon Jun 14 16:21:26 GMT 2021

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

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

Back to the top