Hi,
Some time ago there was this discussion that started with Rick proposing an easy method of defining class constants and ended, after a lot of confusion from my side with some concern about cluttering the .environment en classname clashes.
Since then I've been thinking off and on about that subject and last night I got this idea that I worked out (roughly) today.
So here is a zip file with 5 files:
a. YellowPages.cls
b. YellowPages.rxp - a .properties file
c. test.cls
d. table.cls
e. testYellowPages.rex - to test the concept
Please take the time to unzip it to a directory of your choice, examine the files and execute the testYellowPages.rex to see what I mean.
I have 2 questions for the experts:
tia,
Ruurd
Anonymous
Some files to test an idea
Logged In: YES
user_id=1125291
Originator: NO
Not really sure what part you're uncertain about how it works. Everything appears to be doing what I'd expect, though it took me a little while to figure out that you were using the DO instruction as a replacement for IF.
Currently, there's not much of of an option for loading the classes. One problem you'll run into is the classes loaded this way can't be referenced by directive statements. You'll also have problems with referencing classes across units this way. Also, you may not realize it's happening, but every time you call your class file, you're loading a totally new class object each time you call it.
I think the namespace collision problems can be easily resolved by adding a package prefix on a ::REQUIRES. This would change the lookup names to include the designated prefix on the lookup names in the context of the source file usin the ::REQUIRES.
Logged In: YES
user_id=1847232
Originator: YES
Well I was under the impression that a private class could only be referenced within the same program unit and I'm passing back an instance to the caller?
Yeah, the DO for the IF, I've been doing that for years, it's a habit I can't seem to get rid off.
The DIRECTIVE restriction I understand and had thought of myself, but what do you mean with cross-unit referencing?
Ah the class is loaded again and again! Not good I guess.
Ok down into the wastebasket, I'll wait for your prefix. Thanks for answering.
Ruurd
Logged In: YES
user_id=1125291
Originator: NO
The referencing of a class refers only to what classes are included in the environment variable lookup. It's perfectly fine to create an instance of a class and pass it back to a calling program. In fact, a better way for your program to work would be to pass back the class object directly rather than create an instance. One passed back that way will quite happily accept NEW messages. Done that way, your yellow pages becomes just a lookup mechanism for class objects.
Logged In: YES
user_id=1847232
Originator: YES
I've not looked much at the "private parts" B-), so I wasn't sure.
And for the class object you only need to call it once!
I knew there had to be SOME good in it.
Ruurd
Logged In: YES
user_id=1847232
Originator: YES
So given the setup for the class file (ie: returning the class object and declaring the class private) the simplest form of invocation (without the lookup mechanism) would just be a normal external function call like:
mytestclass = test.cls()
Phew, quite a detour to come to that conclusion!