|
Re: Problem with multiple inheritance [message #421108 is a reply to message #421107] |
Thu, 24 July 2008 13:34 |
Eclipse User |
|
|
|
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
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03311 seconds