Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem with multiple inheritance
Problem with multiple inheritance [message #421107] Thu, 24 July 2008 13:13 Go to next message
Timothy Marc is currently offline Timothy MarcFriend
Messages: 547
Registered: July 2009
Senior Member
Hi together,

i have a problem with multiple inheritance and the way, it is generated from
EMF. Let's set up my scenario:

Element A{
}

Element B extends A{
name:String
getQualifiedName():String
}

Element C extends A

Element D extends B

This is my foundation strcuture for my metamodel. Some element have a name
(like UML::NamedElement) and there is a root element with no name (like
UML::Element).
In another Package i used both C and D as the base classifiers for Element X

Element X extends C,D

After generating the code, the EMF generates something like this:

public class XImpl extends CImpl implements D

with the result, that the getQualifiedName() method isn't actually not
implemented. Only the volatile stub (in fact, the qualified name property is
declared as volatile) is generated. That causes me an
UnsupportedOperationException if i programmatically call the
getQualifiedName() method. I know this depends on the only single element
inheritance mechanism of Java, but it is a pitty for me.

Does anyone knows a good idea how to work around this or must i implement
the getQualifiedName() method again in XImpl?

Hope, this was clear so far.

Thx
Timothy
Re: Problem with multiple inheritance [message #421108 is a reply to message #421107] Thu, 24 July 2008 13:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Timothy,

Yes, EMF does its best to implement multiple inheritance, and it works
very well for structural features. As you have noticed, though,
EOperations need to be replicated as well, so it is necessary to repeat
their bodies.

There are a couple of solutions that are implemented in practice:

- you can specify the body of the EOperation in an annotation
in your Ecore model. This would then be inserted into every
occurrence of the operation
- you can follow the pattern that MDT UML2 actually generates
for you, by externalizing operation bodies into static
XyzOperations classes for each EClass. The operations in the
XyzImpl simply delegate to the XyzOperations, passing 'this' as
the first argument (it's a neat twist on the Foreign Method
pattern, only not quite foreign). So, in each occurrence of
the EOperation in your generated model, you need only paste
the delegation. Then any updates to the operation body need
only be maintained in one place.

The latter approach is definitely my own personal recommendation. And,
as I mentioned, the MDT UML2 component's extensions to EMF's codegen
actually implement this pattern for you.

HTH,

Christian

Timothy Marc wrote:
> Hi together,
>
> i have a problem with multiple inheritance and the way, it is generated from
> EMF. Let's set up my scenario:
>
> Element A{
> }
>
> Element B extends A{
> name:String
> getQualifiedName():String
> }
>
> Element C extends A
>
> Element D extends B
>
> This is my foundation strcuture for my metamodel. Some element have a name
> (like UML::NamedElement) and there is a root element with no name (like
> UML::Element).
> In another Package i used both C and D as the base classifiers for Element X
>
> Element X extends C,D
>
> After generating the code, the EMF generates something like this:
>
> public class XImpl extends CImpl implements D
>
> with the result, that the getQualifiedName() method isn't actually not
> implemented. Only the volatile stub (in fact, the qualified name property is
> declared as volatile) is generated. That causes me an
> UnsupportedOperationException if i programmatically call the
> getQualifiedName() method. I know this depends on the only single element
> inheritance mechanism of Java, but it is a pitty for me.
>
> Does anyone knows a good idea how to work around this or must i implement
> the getQualifiedName() method again in XImpl?
>
> Hope, this was clear so far.
>
> Thx
> Timothy
>
>
Re: Problem with multiple inheritance [message #421111 is a reply to message #421107] Thu, 24 July 2008 16:00 Go to previous message
Enrico Schnepel is currently offline Enrico SchnepelFriend
Messages: 121
Registered: July 2009
Senior Member
hi Timothy

> Element X extends C,D
it may be possible that the opposite order for the extends works, but I
havn't tested it:
Element X extends D,C

regards

enrico
Previous Topic:[Teneo] Multi thread commit and unique annotation
Next Topic:[Net4j/CDO] Connection loss with TCP
Goto Forum:
  


Current Time: Mon Sep 23 23:41:04 GMT 2024

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

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

Back to the top