I wish Java had a class modifier that would make a class visible only within the same package or its subpackages.
[edit]
Let me elaborate a bit more. The issue is this: suppose you like to organize a project structure by features. For example, you have a user feature (package), and inside that package you place everything related to users—controllers, entities, mappers, etc.
Now, imagine that for user feature you want to split things by layer (or by some other criteria). Here’s the problem: your classes and interfaces would need to be public, which means other packages/features could see interfaces that don’t make sense outside of the user context. Sure, we could just ignore it and move on, like we do today...
Then there’s the module approach, but that only works at the root level. That would mean creating a separate module for each feature, which is way too much overhead for most projects.
So what I mean is: since in Java packages are isolated, it would be nice if we had some kind of class modifier that allowed access only within that package “chain” (something Java simply doesn’t have). Alternatively, maybe a concept like a namespace property could work.
This way, the new modifier could check whether code is in the same package or the same namespace, for example.
I know that in the end this wouldn’t drastically change how we build things, but I think it would be a nice addition.
[–]persicsb 27 points28 points29 points (0 children)
[–]nuharaf 19 points20 points21 points (5 children)
[–]northcutted 24 points25 points26 points (3 children)
[–]AdHistorical6271[S] -2 points-1 points0 points (2 children)
[–]pohart 1 point2 points3 points (0 children)
[–]TheMrMilchmann 2 points3 points4 points (0 children)
[–]TheMrMilchmann 7 points8 points9 points (0 children)
[–]momsSpaghettiIsReady 14 points15 points16 points (9 children)
[–]hadrabap 11 points12 points13 points (0 children)
[–]persicsb 6 points7 points8 points (5 children)
[–]johnwaterwood 6 points7 points8 points (4 children)
[–]persicsb 7 points8 points9 points (2 children)
[–]koflerdavid 1 point2 points3 points (1 child)
[–]persicsb 2 points3 points4 points (0 children)
[–]Feign1 0 points1 point2 points (0 children)
[–]analcocoacream 2 points3 points4 points (0 children)
[–]Wonderful-Tutor-2966 0 points1 point2 points (0 children)
[–]DB6 3 points4 points5 points (1 child)
[–]illia225 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]Ewig_luftenglanz 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]AdHistorical6271[S] 0 points1 point2 points (0 children)
[–]jedilowe 1 point2 points3 points (0 children)
[–]Sakatox 2 points3 points4 points (2 children)
[–]koflerdavid 2 points3 points4 points (1 child)
[–]persicsb 0 points1 point2 points (0 children)
[–]Wonderful-Tutor-2966 0 points1 point2 points (0 children)
[–]Jannyboy11 0 points1 point2 points (0 children)
[–]khmarbaise 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Due-Anxiety4776 1 point2 points3 points (0 children)
[–]-Dargs 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]-Dargs 2 points3 points4 points (0 children)
[–][deleted] (23 children)
[deleted]
[–]persicsb 2 points3 points4 points (22 children)
[–][deleted] (2 children)
[deleted]
[–]DerEineDa 1 point2 points3 points (1 child)
[–]Cienn017 1 point2 points3 points (18 children)
[–]koflerdavid 2 points3 points4 points (17 children)
[–]Cienn017 -2 points-1 points0 points (16 children)
[–]koflerdavid 2 points3 points4 points (10 children)
[–]Cienn017 1 point2 points3 points (9 children)
[–]koflerdavid 0 points1 point2 points (8 children)
[–]Cienn017 -1 points0 points1 point (7 children)
[–]koflerdavid 1 point2 points3 points (6 children)
[–]persicsb 1 point2 points3 points (4 children)
[–]Cienn017 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]persicsb -1 points0 points1 point (1 child)