oop - Why Is Java Missing Access Specifiers? -


Does anybody understand why Java is missing:

  • An access specifier that class And all the subclasses, but not by the other classes in the same package? (Protected-minus)
  • An access specifier that allows class, all classes in the same package, and all classes in any sub-package? (Default-plus)
  • An access specifier that currently adds classes to sub-packages to entities with permissions allowed to enter? (Protected-Plus)

Wish I had more options than Safe and Default, especially, I am interested in Protected-More Options

Say I'm trying to make an object I want to use a builder / factory pattern class with many links of other objects. Constructors are all default on objects, because I want to emphasize that linking is done properly, for example using a factory class. I want to put factories together in the sub-package together and all that they are doing immediately - it seems like a cleaner package structure just for me.

No, at present. I have to put builders in the packages they are building objects so that they can get access to the default. But by separating project.area.objects, project.area.objects.builders would be great.

So why is Java a lack of these options? And, is it fake?

To answer your questions once:

  * An access specifier that allows access to classes and all subclasses, but not by other classes in the same package? (Protected-minus)  

It was in Java 1.0 ( Personal Protected ) and was removed. I was totally clear on why not, but it was definitely seen as not worth the trouble. In the current system, all modifiers can go to restricted to less restricted, which can be as simple (less potential variation) ), Which is a Java design goal.

  * An access specifier which allows access by class, all classes in the same package, and all classes in any sub-package? (Default-plus) * An access specifier which adds classes to sub-packages to institutions, is currently allowed to access by protected? (Protected-Plus)  

Both of these are not available for a related reason. There is currently no concept of sub-package in Java, it just pretends the fact that to find regular files and jar based classmoders (as well as compiler), follow the directory structure of the built-in file system. Java will be addressing more widely with JSR 294 ("SuperPackage") (as told by others) that you have been published outside the package, will give more granular control over it (and so if you want to You can make things public, and it will not still be visible).


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -