Menu

#1616 .object~enhanced(.METHODS) does not work with private attributes

v4.2.0
invalid
nobody
None
none
1
2019-03-25
2019-03-24
No
/* Test enhanced with private attributes */
DO i OVER .METHODS
  SAY "Method:" i
END
SAY "attr_pub:" .object~enhanced(.METHODS)~attr_pub
SAY "attr_priv:" .object~enhanced(.METHODS)~attr_priv
EXIT
::ATTRIBUTE attr_pub GET PUBLIC
  RETURN "pub"
::ATTRIBUTE attr_priv GET PRIVATE
  RETURN "priv"

results in

Method: ATTR_PRIV
Method: ATTR_PUB
attr_pub: pub
     9 *-* SAY "attr_priv:" .object~enhanced(.METHODS)~attr_priv
Error 97 running D:\BatCmd\enhanced.rex line 9:  Object method not found
Error 97.1:  Object "enhanced Object" does not understand message "ATTR_PRIV"

I can't see anything which says that this will only work with public methods. .METHODS clearly contains the private method, and it is all in the same file, so the difficulty lies elsewhere.

Discussion

  • Gil Barmwater

    Gil Barmwater - 2019-03-24

    The problem is not with ~enhanced() but with what the example is trying to do. .object~enhanced(.METHODS) creates an object that has two attributes/methods. One is public and one is private. The private one can only be accessed from other methods of the same object, not from an "outside" user. As the Ref. says "A private method is like an internal subroutine." so this is working as expected.

     
  • Graham Norris

    Graham Norris - 2019-03-24

    So you are efffectively saying that private floating methods are unusable, and always will be?

     
  • Erich

    Erich - 2019-03-24
    • status: open --> invalid
     
  • Erich

    Erich - 2019-03-24

    Graham, this is not a bug. Private methods can only be invoked from specific calling contexts - for details see rexxref 4.2.8. Public and Private Methods.

     
  • Graham Norris

    Graham Norris - 2019-03-24

    Bug or not, if they can't ever be used, private floating methods are useless. What is a specific calling context which can be applied to them, if there is one?

     
    • Rony G. Flatscher

      Graham, please study the docs first, before drawing conclusions too early.

       
  • hex

    hex - 2019-03-24

    Why would one want to use a private floating method ?
    Put the methods in a class and private become useful.
    What are you trying to achieve ?

     
  • Graham Norris

    Graham Norris - 2019-03-25

    Rony, thank you for your comment.

    hex, the example above is of course, not useful. What I want is a public floating attribute which references a private floating attribute, but I can't do that because private floating methods are apparently (and no-one has demonstrated that they aren't) unusable. The addition of package floating methods to 5.0 suggest that at some point this problem was recognised and addressed.

     
  • Rony G. Flatscher

    Graham, as Rick has pointed out that floating methods (method, attribute, constant directives that are not assigned to a class) are used in situations (and are quite handy) where one has a need to dynamically assemble classes and their methods under the programmer's control.

    Your samples try out the concepts, but sometimes the assumptions or expectations do not match the sample.

    Here you see a slightly changed version of your own program which uses private methods. So your conclusion, that floating private methods are useless does not hold.

    /* Test enhanced with private attributes */
    DO i OVER .METHODS
      SAY "Method:" i
    END
    SAY "attr_pub:" .object~enhanced(.METHODS)~attr_pub
    SAY "attr_priv:" .object~enhanced(.METHODS)~do_the_secret
    EXIT
    
    ::Method   do_the_secret
         return "Method DO_THE_SECRET: self~attr_priv:" self~attr_priv
    
    ::ATTRIBUTE attr_pub GET PUBLIC
         RETURN "pub"
    ::ATTRIBUTE attr_priv GET PRIVATE
         RETURN "priv"
    

    If you run the program, this is its output:

    G:\test\oorexx\floatingMethods>test.rex
    Method: ATTR_PRIV
    Method: DO_THE_SECRET
    Method: ATTR_PUB
    attr_pub: pub
    attr_priv: Method DO_THE_SECRET: self~attr_priv: priv
    
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB