|
|
|
Re: How to implement an interface in Ecore Model Editor [message #1006723 is a reply to message #1006718] |
Fri, 01 February 2013 15:09 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Anders,
Comments below.
On 01/02/2013 3:47 PM, Anders Jönsson wrote:
> I created an EMF interface with instance type name
> com.riiplan.time.Time, as advised. But, as you can see from my class:
>
> public interface Event<T extends Time> extends CDOObject, Time {
>
> I also use Time as a bounds for a generic type T. Therefore Time was
> already modeled as a DataType.
You could model it either way, or both ways...
> There cannot be two entities with name Time
No, but the data type name doesn't matter, nor does the name for the
wrapper EClass.
> so I deleted the DataType-Time and substituted it for the new
> interface-Time.
>
> But this fails. I have an attribute in Event, called timePoint, typed
> as T.
Yes, you'd want an EDataType for that. You can have both an EDataType
wrapper and an EClass wrapper; they must have different names but can
wrap the same instance type.
> This gives an exception in the get method of EventImpl:
> public T getTimePoint() {
> return (T)eGet(EventPackage.Literals.EVENT__TIME_POINT, true);
> }
>
> The Exception is:
> java.lang.ClassCastException: com.riiplan.time.impl.ImmutableTimeOfDay
> cannot be cast to org.eclipse.emf.ecore.InternalEObject
> at
> org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$InternalSettingDelegateSingleEObject.dynamicGet(EStructuralFeatureImpl.java:2556)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1027)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1011)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1003)
> at
> com.riiplan.mdl.event.impl.EventImpl.getTimePoint(EventImpl.java:162)
> at com.riiplan.mdl.event.impl.EventImpl.getTime(EventImpl.java:180)
>
> I am confused. Will backtrack to Time being a DataType and make Event
> implement Time by hand.
I wonder now if what you're doing makes sense. Does time define a
meaning for equals?
>
>
>> Is it okay that Event itself extends Time?
> No!
What's what you're showing though:
public interface Event<T extends Time> extends CDOObject, Time {
I would imagine that an Event should have a Time, not be a Time,
especially given that you want Time to be a data value and likely want
to define hashCode and equals for it, which are methods you should never
override in your modeled object implementation classes.
>
> ///Anders
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Re: How to implement an interface in Ecore Model Editor [message #1007108 is a reply to message #1007094] |
Mon, 04 February 2013 13:36 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Andrers,
Comments below.
On 04/02/2013 1:41 PM, Anders Jönsson wrote:
> I see...
>
> 1. I will probably change my design so that there is a clear
> distinction between my data types (like TimePoint) and my "classes"
> like Events.
Yes, you want to think carefully about that. Instances of EDataTypes
should generally be immutable value objects; they'll typically
specialize hashCode and equals. Instances of EClass are mutable and
notify when they mutate; they should not specialize hashCode and equals.
> Will probably let Events implement something like TimeEvent instead. I
> REALLY appreciate you taking the time to point these things out.
>
> 2. Just to see if I got it right: When it comes to
> persistens/serialization you cannot have an interface that is
> implemented by both an EClass and an EDataType because:
You can, but it probably means you're doing something wrong or at least
very unusual.
> - An EClass cannot be serialized as an EAttribute?
It could, but you lose "identity" and it only works if you write the
createFromString/convertToString logic. It doesn't make a lot of sense
and is most likely wrong.
> - You cannot have an EReference to an EDataType at all?
No. The generic type of an EReference must erase to an EClass and the
generic type of an EAttribute must erase to an EDataType. In some
places where you want either (the ChangeModel's FeatureChange is a good
example) you'd have to model both an attribute and a reference...
>
> ///Anders
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03219 seconds