On Wednesday, May 20, 2020 at 5:49:28 PM UTC-4,
[email protected] wrote:
So without EXPOSE, an attribute's not visible to the methods IN THE SAME CLASS? Isn't that a little weird?
An attribute is not a variable, it is a shorthand for declaring methods. The attribute is only accessed by sending a message to the object. If you wish, you can use "self~attributeName" in the init method to accomplish the same thing, but using expose is
much more efficient.
In that case what do PUBLIC and PRIVATE mean on an ::attribute? Oh, I guess only whether the attribute is available to the main program. Still weird.
PRIVATE means the same as it does with any method declaration. It determines what happens when you send a message to that object from a different scope. Declaring an attribute PRIVATE means it can only be accessed from a method running on the same object
instance. This is most useful if you have attributes that you do not want widely available, but are still available to subclasses of the declaring class.
Don't get me wrong, I love REXX - been using it for decades now - and I love oo programming, once I finally got the hang of it. So I expect to love ooRexx...once I get the hang of it :).
Ok, next question: My method now assigns values correctly, once I add the EXPOSE statement. But it doesn't seem to work for a constant:
::class C
::constant typs 'TESOV'
::method init
expose typs
say typs
::CONSTANT is also just a short hand method declaration. It only returns that value when invoked via "~". It does NOT set any instance variables of the object.
When I create a new object of type C, it displays "TYPS"; the INIT method apparently can't see the constant. My main program can, though; when I ask it to SAY OBJ~TYPS it displays "TESOV". Same question, I guess; what am I missing? Notice I
attempted to use EXPOSE, but that apparently didn't do the job.
To access the declared constant value, use "self~typs".
--- On Wednesday, May 20, 2020 at 6:24:03 AM UTC-4, Rick McGuire wrote:
Expose makes the object variable available to the method (including INIT). With out the EXPOSE instruction, your INIT method is just assigning values to local variables that will go away once the method terminates.
--- On Wednesday, May 20, 2020 at 12:55:46 AM UTC-4, [email protected] wrote:
...I see in the documentation that the ::attribute directive ... well, I think it's equivalent to establishing a "property" in VBA. So I write a simple program like this:
opar=.par~new('E')
say opar~typ opar~hdr opar.fvar
opar~hdr="Explanation"
say opar~typ opar~hdr opar.fvar
exit
::class Par
::attribute typ --1 char
::attribute hdr --text
::attribute fvar --boolean
::method init
trace 'I'
arg typ
select
when typ='A' then do; fvar=0; hdr="Alpha"; end
when typ='E' then do; fvar=1; hdr='Explanation'; end
otherwise nop; end
...it says here EXPOSE makes variables available to methods, whereas what I want is the reverse, to make attributes available to the main program, ie the caller of the class. And anyway the documentation explicitly says that the ::attribute
statement creates two methods, like this:
::method "NAME=" /* attribute set method */
expose name /* establish direct access to object variable (attribute) */
use arg name /* retrieve argument and assign it to the object variable */
::method name /* attribute get method */
expose name /* establish direct access to object variable (attribute) */
return name /* return object's current value */
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)