Object Oriented Programming with D Language. Private access specifier. Summary.

Lutger lutger.blijdestijn at gmail.com
Fri Aug 22 02:47:54 PDT 2008


DF wrote:

...
> I try to summary what I wanted to ask and say.
> 
> 1) Why D language OO "private" access specifier is made "module public"
> (e.g. method can be accessed by any other class or function inside the
> same module, "private" field can be accessed and CHANGED by any other
> class or function inside the same module)?

My 2 cents is that your assumption that private is exclusively related to OO
programming is wrong. Private provides encapsulation, but that is not
restricted to OO programming. As has been said, it is on the module level,
not coincidentally corresponding to a single file. 
 
> -- To my point of view if you want to implement such a communication is a
> single module between two classes or a function and a class just make
> "module public" access specifier, "private" should be private (e.g.
> restricts the access to the class itself. Only methods that are part of
> the same class can access private members.)

In D it should be done the other way around: if you want to restrict private
access to a single class, design your modules to use one class per file.
 
> 2) What's the difference between module and package?
> 
> -- Maybe that's where I'm wrong, because it is the same things to me.

They are not the same, a module corresponds to a file, a package corresponds
to one directory containing a set of modules. 



More information about the Digitalmars-d mailing list