[EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745049] |
Tue, 04 October 2016 09:41  |
Eclipse User |
|
|
|
Hi,
I started recently with EMF and i have a doubt:
If i have class diagram like this:
A -----> B
In the generated code of A i see:
with lower bound = 0 or with lower bound = 1. So in the new Eclipse instance started to populate the model, initial value of property B in an instance of A is not set, then i can set it with a reference to B or return it to initial value. So are there any differences between lower bound = 0 and lower bound = 1 of reference? In the case of lower bound = 1 i was expecting to be able to create an instance of A only then an instance of B to have a consistent value with the lower bound constraint.
Thank you all.
Marco
|
|
|
Re: [EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745052 is a reply to message #1745049] |
Tue, 04 October 2016 10:04   |
Eclipse User |
|
|
|
Hello,
By default, no instance is automatically created for a reference, whether the lower bound is 0 or 1.
The main difference when you change the lower bound, I think, is during the validation of your model : if a lower bound 1 reference is null, you'll have an error.
Now, I suppose your need is to automatically create an instance of B when you create A, isn't it ?
I'm not sure what is the best approach, but you can :
- edit your ModelFactory.createA() (in the model generated code) (no, never do that)
- edit the create command in the edit model (in the edit generated code).
Aurélien.
[Updated on: Tue, 04 October 2016 16:09] by Moderator
|
|
|
|
|
Re: [EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745377 is a reply to message #1745068] |
Sun, 09 October 2016 06:28  |
Eclipse User |
|
|
|
Hi
As Ed M points out: today, the main difference between [0..1] and [1..1] is that validation will behave differently. This is a modeling activity. You will find that this now affects null-safe navigation warnings in OCL, and may affect the performance and even results of model transformations.
At the Java level the difference is almost irrelevant, since the Java support tends to support transient construction states where mandatory elements may be uninitialized. With the advent of @NonNull annotations, there is case that EMF might evolve to declare @NonNull when getting / setting [1..1] features, perhaps adding a basicGet if you really want the uncertain value. However EMF has such a substantial legacy that such an evolution may be untenable even if funding is provided.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.04247 seconds