So without EXPOSE, an attribute's not visible to the methods IN THE SAME CLASS? Isn't that a little weird?
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.
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
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.
--- 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,
robhb...@gmail.com 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: