www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why has base class protection been deprecated?

reply David Bryant <bagnose gmail.com> writes:
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
Apr 24 2012
next sibling parent reply Don Clugston <dac nospam.com> writes:
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.
Apr 24 2012
parent reply David Bryant <bagnose gmail.com> writes:
 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.
Apr 24 2012
parent reply Don Clugston <dac nospam.com> writes:
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.
Apr 24 2012
parent reply David Bryant <bagnose gmail.com> writes:
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.
Apr 24 2012
parent David Bryant <bagnose gmail.com> writes:
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.
Apr 24 2012
prev sibling parent "David Nadlinger" <see klickverbot.at> writes:
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
Apr 24 2012