www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why is protected not also implicit package?

reply Frank Benoit <keinfarbton googlemail.com> writes:
While porting Java code this is kind of annoying.
In Java a protected member is also accessbible from the package.
And I think this would also make sense for D.

What i end up doing is often this pattern:

// existing method
protected int meth( double a, Object b ){
  //...
}
// added from me
package int meth_package( double a, Object b ){
  return meth( a, b );
}

Then replace all reference from within the package with meth_package.
This works, but is so ugly.

Or how about allowing the combination of protected and package like this?
protected package int meth( double a, Object b ){
  //...
}
Aug 26 2008
parent Sergey Gromov <snake.scaly gmail.com> writes:
Frank Benoit <keinfarbton googlemail.com> wrote:
 While porting Java code this is kind of annoying.
 In Java a protected member is also accessbible from the package.
 And I think this would also make sense for D.
I think that D is closer to C++ than to Java. In C++, private and protected are class-scoped. In D they're module-scoped but are easily reduced to class scope if you write one class per module. D way allows for better control over method visibility: you can separate polymorphic interface and library interface. Java forces you to publish any polymorphic methods to the library. As to porting, it sounds easier to make all protected members public--- this doesn't chane much compared to Java. -- SnakE
Aug 29 2008