www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - should protected imply package?

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
In Java, "protected"-level protection implies package-level protection 
(see e.g. 
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html). 
Should we copy that behavior in D, or take advantage of the package 
keyword and require it as in "package protected"?


Andrei
Sep 24 2009
next sibling parent Jeremie Pelletier <jeremiep gmail.com> writes:
Andrei Alexandrescu wrote:
 In Java, "protected"-level protection implies package-level protection 
 (see e.g. 
 http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html). 
 Should we copy that behavior in D, or take advantage of the package 
 keyword and require it as in "package protected"?
 
 
 Andrei
I make a clear distinction between 'protected' which can be accessed by any subclasses no matter their modules or packages, and 'package' which is like public but for the current package only. Jeremie
Sep 24 2009
prev sibling next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Andrei Alexandrescu:

 In Java, "protected"-level protection implies package-level protection 
 (see e.g. 
 http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html). 
 Should we copy that behavior in D, or take advantage of the package 
 keyword and require it as in "package protected"?
If you are interested in Java Packages you can also take a look at Java superpackages: http://today.java.net/pub/a/today/2008/03/06/jsr-294-superpackages.html Bye, bearophile
Sep 24 2009
prev sibling next sibling parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Thu, Sep 24, 2009 at 1:38 PM, Andrei Alexandrescu
<SeeWebsiteForEmail erdani.org> wrote:
 In Java, "protected"-level protection implies package-level protection (see
 e.g.
 http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html).
 Should we copy that behavior in D, or take advantage of the package keyword
 and require it as in "package protected"?
Under the current implementation, if protected implied package, all protected methods would suddenly become nonvirtual, since for some reason, package is treated as a kind of 'private'. Not really what you'd want, I think ;) 'package' should not conflate visibility and virtuality. If it didn't do that, having protected imply package would be just fine.
Sep 24 2009
parent "Denis Koroskin" <2korden gmail.com> writes:
On Thu, 24 Sep 2009 23:36:46 +0400, Jarrett Billingsley  
<jarrett.billingsley gmail.com> wrote:

 On Thu, Sep 24, 2009 at 1:38 PM, Andrei Alexandrescu
 <SeeWebsiteForEmail erdani.org> wrote:
 In Java, "protected"-level protection implies package-level protection  
 (see
 e.g.
 http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html).
 Should we copy that behavior in D, or take advantage of the package  
 keyword
 and require it as in "package protected"?
Under the current implementation, if protected implied package, all protected methods would suddenly become nonvirtual, since for some reason, package is treated as a kind of 'private'. Not really what you'd want, I think ;) 'package' should not conflate visibility and virtuality. If it didn't do that, having protected imply package would be just fine.
Can't agree more!
Sep 24 2009
prev sibling parent reply Don <nospam nospam.com> writes:
Andrei Alexandrescu wrote:
 In Java, "protected"-level protection implies package-level protection 
 (see e.g. 
 http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html). 
 Should we copy that behavior in D, or take advantage of the package 
 keyword and require it as in "package protected"?
 
 
 Andrei
Java might be a good source of inspiration. Sorting out what 'package' should mean is one of the big remaining issues in D. The current 'package' is a broken implementation of a broken concept. As in one of the bugzilla bugs "package does not work at all". But even if it did work as advertised, it would still suck. Can we announce it as deprecated until we work out what to do with it? We should discourage everyone from using it right now, it's completely broken.
Sep 25 2009
parent Max Samukha <spambox d-coding.com> writes:
Don wrote:

 Andrei Alexandrescu wrote:
 In Java, "protected"-level protection implies package-level protection
 (see e.g.
 http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html).
 Should we copy that behavior in D, or take advantage of the package
 keyword and require it as in "package protected"?
 
 
 Andrei
Java might be a good source of inspiration. Sorting out what 'package' should mean is one of the big remaining issues in D. The current 'package' is a broken implementation of a broken concept. As in one of the bugzilla bugs "package does not work at all". But even if it did work as advertised, it would still suck. Can we announce it as deprecated until we work out what to do with it? We should discourage everyone from using it right now, it's completely broken.
What about deprecating "package" and employing "protected" to mean "accessible from the package, its sub-packages and, if it is a class member, from subclasses in other packages"? The model would be almost equivalent to Java's except we don't need Java's "package-private" (no modifier) because of D's "public by default, private is accessible from anywhere inside the module".
Sep 25 2009