Help save net neutrality! Learn more.
Close

#59 YellowPages aka avoiding classname clashes?

3.2.0
closed
Sample (19)
5
2012-08-14
2007-11-07
No

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:

  1. Is it supposed to work the way it works?
  2. Are there other, easier or better ways to get the same result?

tia,

Ruurd

Discussion

  • Ruurd Idenburg

    Ruurd Idenburg - 2007-11-07

    Some files to test an idea

     
  • Rick McGuire

    Rick McGuire - 2007-11-07

    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.

     
  • Ruurd Idenburg

    Ruurd Idenburg - 2007-11-07

    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

     
  • Rick McGuire

    Rick McGuire - 2007-11-07

    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.

     
  • Ruurd Idenburg

    Ruurd Idenburg - 2007-11-08

    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

     
  • Ruurd Idenburg

    Ruurd Idenburg - 2007-11-08

    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!

     


Anonymous

Cancel  Add attachments