|Re: Dynamic subclassing of static model classes [message #431922 is a reply to message #431909]
||Wed, 29 July 2009 16:46
| Ed Merks
Registered: July 2009
Mario Winterer wrote:
> I've played around with dynamic models recently and discovered some
> flaws when I've tried to dynamically subclass a static (generated)
> model class. Please let me know if I should file bugs for that issues!
> (1) It is not possible to instantiate a non-abstract dynamic subclass
> of an abstract static base class, as the EFactory-instance tries to
> create an instance of the 'nearest' static base class on instantiation
> which fails due to it is abstract.
> (A possible solution is discussed in 3)
Yes, this is a limitation. Clearly it's impossible to instantiate an
abstract class and yet it's needed to act as the base in order for the
dynamic instance to behave exactly like the existing implementation...
> (2) If a dynamic class is defined and added to a static package, the
> package factory will still not be able to instantiate the dynamic
> class, because the factory is generated too and only checks the static
You can't change generated meta data at all.
> Although adding dynamic classes to static packages seems to be dirty,
> maybe super.create(EClass) should be called instead of throwing an
No, it's just not supported.
> (3) When I use multiple inheritance to subclass two static Ecore
> classes Rectangle and Clickable in one single dynamic class Button,
> the instance b of class Button is java-instanceof
> Rectangle.instanceClass but not java-instanceof
> Clickable.instanceClass, because - as mentioned 1) - the factory
> instantiates the 'nearest' static base class and chooses the first one
> in case of multiple base classes (which is S1 in our example).
> This issue could be fixed by using the Java Proxy API to dynamically
> instatiate a proxy that implements the instance classes (the
> interfaces) of all direct static base classes.
> (Note that this would also fix the issue mentioned in 1)
I played a bit with Java dynamic proxies but in the end, it's not
possible for them to reuse an existing base class like BasicEObjectImpl
so one ends up having to delegate from the proxy to something that
duplicates all the basic implementation behavior and even then you end
up with problems where the "this" of the proxy is not the same object as
that being delegated to.
The simplest approach is simply to not make the base class abstract.
Powered by FUDForum
. Page generated in 0.01488 seconds