ReadOnly Field or Property
-
- Posts: 431
- Joined: Fri Oct 03, 2008 4:14 pm
ReadOnly Field or Property
Often I want a readonly public field that is set once and only once in the constructor. It seems the only to accomplish this is to make it propery, and define a getter function which simply returns the underlying private property. Is this correct? Any other way to do it? This takes a lot of boiler plate code. It seems that the constructor should allow the setting of read-only fields.
- StefanoLanzavecchia
- Posts: 113
- Joined: Fri Oct 03, 2008 9:37 am
Re: ReadOnly Field or Property
Another way would be to allow (like in Ruby) the execution of code, let's say when the script is fixed, to build automatically those properties.
-
- Posts: 431
- Joined: Fri Oct 03, 2008 4:14 pm
Re: ReadOnly Field or Property
Stefano, isn't that what happens now in a class in dyalog? It gets executed when fixed. The problem (for me) is that I want a read-only field instantiated when the instance is created, not when the class is created or fixed.
- StefanoLanzavecchia
- Posts: 113
- Joined: Fri Oct 03, 2008 9:37 am
Re: ReadOnly Field or Property
What I was suggesting was a way to obtain executing code the structure you proposed (i.e.: a property without the setter). The ":Property" in the script prevents this from happening and []FX'ing a function that ":implements" the property getter doesn't seem to work.
- JohnD|Dyalog
- Posts: 74
- Joined: Wed Oct 01, 2008 9:35 am
Re: ReadOnly Field or Property
StefanoLanzavecchia wrote:Another way would be to allow (like in Ruby) the execution of code, let's say when the script is fixed, to build automatically those properties.
And I believe (memory's not what it was, and I'm too busy to check), that you can assign to a readonly field at class fix time.
-
- Posts: 431
- Joined: Fri Oct 03, 2008 4:14 pm
Re: ReadOnly Field or Property
John, I hope so, otherwise how would a readonly field every get a value? ;)