Object Oriented Programming with D Language. Private access specifier.

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Aug 21 15:23:21 PDT 2008


"Robert Fraser" <fraserofthenight at gmail.com> wrote in message 
news:g8kh4k$5jc$1 at digitalmars.com...
> Lars Ivar Igesund 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.
>>> It's a feature -- a replacement for "friend" in C++. The general idea of
>>> 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).
>>
>> package is implemented to mean that something is accessible to other 
>> modules
>> in the same package.
>
> I meant that (last I checked), DMD doesn't enforce it.

For a long time that was true but it has seemed to more or less enforce it 
since about 1.0.  I think there may still be some bugs with more complex 
cases but it does seem to work for the basic case. 





More information about the Digitalmars-d mailing list