April 24, 2012
With the dmd 2.059 I have started getting the error 'use of base class protection is deprecated' when I try to implement an interface with private visibility, ie:

  interface Interface { }

  class Class : private Interface { }

 $ dmd test.d
 test.d(4): use of base class protection is deprecated

This bothers me for two reasons: firstly it's not a base class, and secondly, it's a standard OO pattern of mine.

What's up with this?

Thanks,
Dave
April 24, 2012
On 24/04/12 14:22, David Bryant wrote:
> With the dmd 2.059 I have started getting the error 'use of base class
> protection is deprecated' when I try to implement an interface with
> private visibility, ie:
>
> interface Interface { }
>
> class Class : private Interface { }
>
> $ dmd test.d
> test.d(4): use of base class protection is deprecated
>
> This bothers me for two reasons: firstly it's not a base class, and
> secondly, it's a standard OO pattern of mine.
>
> What's up with this?
>
> Thanks,
> Dave

Because it doesn't make sense. All classes are derived from Object. That _has_ to be public, otherwise things like == wouldn't work.

Previously, the compiler used to allow base class protection, but it ignored it.
April 24, 2012
>
> Because it doesn't make sense. All classes are derived from Object. That
> _has_ to be public, otherwise things like == wouldn't work.
>

Does the same apply for interfaces? I'm specifically implementing an interface with non-public visibility. This shouldn't affect the visibility of the implicit Object base-class.
April 24, 2012
On 24/04/12 15:29, David Bryant wrote:
>>
>> Because it doesn't make sense. All classes are derived from Object. That
>> _has_ to be public, otherwise things like == wouldn't work.
>>
>
> Does the same apply for interfaces? I'm specifically implementing an
> interface with non-public visibility. This shouldn't affect the
> visibility of the implicit Object base-class.

Right. Only classes are affected.
April 24, 2012
On 04/24/2012 11:07 PM, Don Clugston wrote:
> On 24/04/12 15:29, David Bryant wrote:
>>>
>>> Because it doesn't make sense. All classes are derived from Object. That
>>> _has_ to be public, otherwise things like == wouldn't work.
>>>
>>
>> Does the same apply for interfaces? I'm specifically implementing an
>> interface with non-public visibility. This shouldn't affect the
>> visibility of the implicit Object base-class.
>
> Right. Only classes are affected.

Ok...so I still don't understand why the original example shouldn't compile. I'm not trying to change the visibility of the base class but rather the visibility of the interface.
April 24, 2012
On 04/24/2012 11:47 PM, David Bryant wrote:
> On 04/24/2012 11:07 PM, Don Clugston wrote:
>> On 24/04/12 15:29, David Bryant wrote:
>>>>
>>>> Because it doesn't make sense. All classes are derived from Object.
>>>> That
>>>> _has_ to be public, otherwise things like == wouldn't work.
>>>>
>>>
>>> Does the same apply for interfaces? I'm specifically implementing an
>>> interface with non-public visibility. This shouldn't affect the
>>> visibility of the implicit Object base-class.
>>
>> Right. Only classes are affected.
>
> Ok...so I still don't understand why the original example shouldn't
> compile. I'm not trying to change the visibility of the base class but
> rather the visibility of the interface.

To be clear: my subject line is misleading. I used that text because it's what came out of the compiler's mouth. I do understand your reasoning why you can't change the visibility of a base class, just not for an interface.
April 24, 2012
On Tuesday, 24 April 2012 at 12:22:14 UTC, David Bryant wrote:
> This bothers me for two reasons: firstly it's not a base class, and secondly, it's a standard OO pattern of mine.
>
> What's up with this?

Generally (and slightly inaccurately) speaking, D follows the Java model for inheritance rather than the C++ one, where base class protection attributes simply do not exist.

Besides that, I'm not quite sure what privately inheriting an interface would buy you – there would be no implementation to inherit anyway (except for final interface methods, but I doubt a valid use case for this would be easy to find)?

David
Top | Discussion index | About this forum | D home