|
|
Re: How to enforce an EReference to be initialized on creation of container [message #1461267 is a reply to message #1461207] |
Tue, 04 November 2014 11:35 |
Ed Merks Messages: 33133 Registered: July 2009 |
Senior Member |
|
|
Thorsten,
Comments below.
On 04/11/2014 11:13 AM, Thorsten Schlathölter wrote:
> Hi,
> I have a question regarding initialization of an EReference which is
> modeled as a containment to is parent object. Is it possible to have
> this EReference be initialized upon creation of the container?
That depends a bit of when/where you want to do that. Certainly you
need to be very cautious about what you do directly in the model code so
as not to break things like deserialization and copying...
So it's not generally a good idea to initialize an object in the
generated constructor, whoever tempting that may be.
If the purpose is to make the user's life easier, it's always reasonable
to create more fully initialized instances in the item providers, e.g.,
org.eclipse.emf.ecore.provider.EGenericTypeItemProvider.collectNewChildDescriptors(Collection<Object>,
Object)
> So that I can omit null checks when accessing the object?
If the issue is more one how you write the logic programmatically, for a
case like that, you might want to provide convenience operations for
that purpose...
>
> For example when I have a Document with MetaData. I would like to
> achieve that document.getMetaData() is never null.
You might have a method document.getOrCreateMetaData() (not the nicest
name, but you can be creative) that ensures null is never returned...
>
> Thx.
> Thorsten
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02130 seconds