Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF and final filed initialization(How initial final field of EMF generated implementation class)
EMF and final filed initialization [message #478910] Fri, 07 August 2009 13:00 Go to next message
Manuel Selva is currently offline Manuel SelvaFriend
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi all,

I am modeling a class with two final (regarding Java) fields, i.e two fields that can't be modified after object's creation.

I saw a changeable attribute in EMF code generator allowing me to not generate setter for these fields.
It works but i am not able to set these fields ....

How should I work witn non changeable fields ? Can you point me to the documention about that ?

Thanks in advance

Manu


Re: EMF and final filed initialization [message #478915 is a reply to message #478910] Fri, 07 August 2009 13:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Manuel,

Comments below.

Manuel Selva wrote:
> Hi all,
>
> I am modeling a class with two final (regarding Java) fields, i.e two
> fields that can't be modified after object's creation.
Not with Ecore you won't. :-P
>
> I saw a changeable attribute in EMF code generator allowing me to not
> generate setter for these fields. It works but i am not able to set
> these fields ....
>
> How should I work witn non changeable fields ? Can you point me to the
> documention about that ?
Typically these are things that will be derived or computed in some way.

You should keep in mind that deserialization involves creating an
object, and then later setting the values of fields. The copier does
this as well. So this notion of something being final after
construction (after the constructor completes) simply doesn't fit with
the other things the framework needs to be able to do. Probably you
need to modify your strategy...
>
> Thanks in advance
>
> Manu


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF and final filed initialization [message #478917 is a reply to message #478915] Fri, 07 August 2009 13:50 Go to previous messageGo to next message
Manuel Selva is currently offline Manuel SelvaFriend
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi Ed,

Once again, thanks for your quick and clear answer.

I guess I will not set the changeable attribute to false and carefully ALWAYS set this two ("final") attributes after creating them using the generated factory.

Is it the "right" way to do ?

Note: I was reviewing some part of my code after reading the excellent "Effective Java" book and was trying to apply it. Here it concerns the item 15 "Minimize mutability" but it seems, as you said, this item is not compatible with EMF framewrok.

Regards,

Manu


Re: EMF and final filed initialization [message #478933 is a reply to message #478917] Fri, 07 August 2009 14:37 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Manu,

Comments below.


Manuel Selva wrote:
> Hi Ed,
>
> Once again, thanks for your quick and clear answer.
>
> I guess I will not set the changeable attribute to false and carefully
> ALWAYS set this two ("final") attributes after creating them using the
> generated factory.
Yes. You might add a factory method where the two feature's values are
specified as arguments as a convenience...
>
> Is it the "right" way to do ?
Yes.
>
> Note: I was reviewing some part of my code after reading the excellent
> "Effective Java" book and was trying to apply it. Here it concerns the
> item 15 "Minimize mutability" but it seems, as you said, this item is
> not compatible with EMF framewrok.
Yes, not so much.
>
> Regards,
>
> Manu


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Super types for model objects
Next Topic:Multiple EMF meta-models in a single plugin
Goto Forum:
  


Current Time: Thu Apr 25 09:36:59 GMT 2024

Powered by FUDForum. Page generated in 0.02377 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top