[Xotcl] Can't call protected class method from instances

Gustaf Neumann neumann at wu.ac.at
Fri Feb 10 19:07:10 CET 2012


Dear Arthur,

the call protection of NX is object-centric defined, which is a strong 
form of protection. A protected method can be only called if the caller 
and the callee are the the same object. In the examples below, caller 
and callee differ. In the first case, the caller is an instance, the 
callee is the class object, in the seconds case, caller and callee are 
two different instances.

So, protection is in nx quite different to class centric approaches 
(e.g. Java/C++); it is as well different to ruby protection (where 
different instances of the same class can all protected methods).

So, the current behavior is as intended; in general, when you have 
convincing evidence, we are always open to relax the nx policy.

-gustaf neumann

Am 10.02.12 11:45, schrieb Arthur Schreiber:
> Hello Gustaf,
>
> Is not being able to call protected class methods from instances intended
> behaviour?
>
> Here is a very simple test case:
>
> package require nx
>
> nx::Class create Greeter {
>      :class protected method say_hi {} {
>          puts "Hello!"
>      }
>
>      :public method say_hi {} {
>          [:info class] say_hi
>      }
> }
>
> [Greeter new] say_hi
>
> Also, protected methods can not be called from instances of the same class,
> e.g.:
>
> package require nx
>
> nx::Class create Greeter {
>      :public method say_hi { other_greeter } {
>          $other_greeter protected_say_hi
>      }
>
>      :protected method protected_say_hi { } {
>          puts "Hello!"
>      }
> }
>
> set g1 [Greeter new]
>
> [Greeter new] say_hi $g1
>
> Kind Regards,
> Arthur
> _______________________________________________
> Xotcl mailing list
> Xotcl at alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl


-- 
Univ.Prof. Dr. Gustaf Neumann
Institute of Information Systems and New Media
WU Vienna
Augasse 2-6, A-1090 Vienna, AUSTRIA



More information about the Xotcl mailing list