digitalmars.D - Re: Object Oriented Programming with D Language. Private access specifier.
- DF <deefriend ymail.com> Aug 22 2008
Jacob Carlborg Wrote:Max Samukha wrote:On Thu, 21 Aug 2008 10:34:29 +0200, Lars Ivar Igesund <larsivar igesund.net> wrote:Robert Fraser wrote:DF wrote:Why can private fields be accessed from other methods or classes in the same module? If I wanted to access them from the same module I would make them package public.
a module is that it is an autonomous code unit controlled by a single developer/team and if you're accessing a private function in the module, you have a good reason to. It's all the same file, so if you're changing something that accesses a private member, you can change the private implementation as well. "package" isn't implemented (sadly -- I find it very useful in Java so that a package has only a single public API).
in the same package.
It would be even more useful if members with package accesibility were accessible not only from the same package but also from its subpackages. Imagine there is a function, data structure or whatever that is used throughout a complex package containing nested packages but is not intended to be accessible by users of this package. Now I have to declare such a function/structure public. 'package' does not help me here.
Could "protected" help here? BTW what happened with "protected"? It's not listed here under protection: http://www.digitalmars.com/d/1.0/class.html "protected" works at least with gdc.
That won't help, if I don't want to have my field in children of a class.
Aug 22 2008