Object Oriented Programming with D Language. Private access specifier.

Jb jb at nowhere.com
Thu Aug 21 18:46:38 PDT 2008


"DF" <deefriend at ymail.com> wrote in message 
news:g8jpsg$18mv$1 at digitalmars.com...
>>
>> Lars Ivar Igesund
>> blog at http://larsivi.net
>> DSource, #d.tango & #D: larsivi
>> Dancing the Tango
>
> It is easy to say that it's ok, than find out why it is ok.
> I'm not saying that D implementation of "private" access specifier is 
> wrong, I just want to know why "private" is implemented in this way.
> Is it just because it solves language-specific problems or there is any 
> other reason for that?

I think the point is that it allows you to have two (or more) classes that 
are entirely visible to each other, but *without being visible to everything 
else.*

It allows you to encapsulate a collection of classes / functions.

For example, you might have some linked list / binary tree type structure 
with different kinds of nodes represented by different classes. If you 
declare all these classes in one module you can actualy hide more of the 
implementation because methods that might only ever be called between these 
classes themselves, need not be visible outside the unit.

Without this mechanism they'd need to be public / package to be visible 
between nodes. And hence that makes them more visible to other parts aswell.






More information about the Digitalmars-d mailing list