Module-level accessibility
Steven Schveighoffer
schveiguy at yahoo.com
Mon Oct 4 11:35:17 PDT 2010
On Mon, 04 Oct 2010 14:29:38 -0400, Denis Koroskin <2korden at gmail.com>
wrote:
> On Mon, 04 Oct 2010 22:26:17 +0400, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>
>>
>> What possible use case could private methods being polymorphic allow?
>>
>> A private method can only be called by the class that contains the
>> implementation. Allowing base classes to call it makes no sense.
>>
>> Make the method protected, it gives the desired effect (including for
>> the example in the bug report as stated by the original reporter).
>>
>> -Steve
>
>
> module private;
> import std.stdio;
>
> class A
> {
> private void foo()
> {
> writeln("hi there");
> }
> }
>
> class B : A
> {
> void test()
> {
> foo();
> }
> }
>
> void main()
> {
> B b = new B();
> b.test();
> }
>
> # dmd private.d && ./private
> hi there!
That works today (aside from using a keyword for the module name), there's
nothing polymorphic about it.
I suppose you may be rebutting my "can only be called by the class that
contains the implementation", yes, I immediately wished to change that
sentence after I sent it out.
But you don't need polymorphism to achieve this.
-Steve
More information about the Digitalmars-d
mailing list