www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Protective Attributes and `alias'

There is nothing I can find in the specs about how protective 
attributes change under the constructs known to D and the reference 
compiler does not follow my assumptions on what is plausible.

For example, if I use more than one protective attribute in a chain 
of accesses to a member of a class, i find it plausible, that the 
maximal protection found in the chain will be applied. But this is 
not true for the reference compiler:

`protected' C2.i is reachable through a `private' alias, whereas 
`private' C1.i is not reachable although made protected by a 
`protected' alias.

Therefore neither minimal nor maximal protection found in a chain 
is used.

A further confusion hits me, when I realize, that one may write to 
C1.i through C2 and any other class derived from C2 after a 
maintenance change, because they are in the same module, although 
one cannot reach C1.i from D1 or any other class derived from C1.

In essence this would mean, that after any maintenance the changed 
part must be put into a separate module to prevent accesses by 
mistake or criminal assault.

-manfred


file depth0.d
---------------------
class C1{
  private int i;
  protected alias i j;
}
class C2{
  protected int i;
  private alias i j;
}
---------------------

file depth1.d
---------------------
import depth0;

class D1: public C1{
  void f(){
    j= 1; // error: "i not accessible"
  }
}
class D2: public C2{
  void f(){
    j= 1; // OK
  }
}
--------------------
Dec 21 2005