Private classes?
Charles D Hixson
charleshixsn at earthlink.net
Tue Aug 21 15:30:41 PDT 2007
Nathan Reed wrote:
> Regan Heath Wrote:
>
>> Try this:
>>
>> [pclassA.d]
>> module pclassA;
>>
>> class A
>> {
>> private this()
>> {
>> }
>> }
>
> Thanks, I am aware of the private constructor trick, but it seems like a slightly hackish workaround. Philosophically, it seems to me that it should be possible to hide a class so other modules (or code outside its outer class) don't even know it exists - this just makes it so they can't instantiate it.
>
> Thanks,
> Nathan Reed
I "sort of" see what you mean, but you slightly misunderstand
the meaning of private in D. private means "not visible
outside of the file in which it is declared". (Well, actually
I think it's supposed to be module rather than file, but I
always program as if the two were synonymous, so any mistakes
this causes aren't noticed by me.
As such, I agree that private classes, should they exist (and
why not?) shouldn't be visible outside of the module (file?)
in which they are declared. This would allow two classes in
different modules to have the same name. But note that
mangling would mean that their names weren't the same anyway.
Stylistically I'd support private classes, but I don't
consider the concept important.
More information about the Digitalmars-d
mailing list