|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
Registered: July 2009
On 04/11/2014 11:13 AM, Thorsten Schlathölter wrote:
> 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.,
> 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
> 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...
Professional Support: https://www.macromodeling.com/
Powered by FUDForum
. Page generated in 0.02347 seconds