Why is there no package visibility modifier in kot...
# announcements
f
Why is there no package visibility modifier in kotlln? For example, I have a package for my DB access in my server. I want to only expose one class to the rest of the app to avoid confusion. In the package I also have several repositorieclasses for each of my enteties, I do not want for example the controllers package to access those repositories directly, I want it instead to go through my master
DB
class. How can I do that in kotlin?
u
Take a look at
internal
modifier
a
package visibility has never made it into kotlin because you could create a class with the same package in another module and get access to the other class in another module
f
But a module is something so much bigger, My server app is always gonna be one module right? Its always one gradle project.
I get that the package modifier provided no real protection and thats why it was removed but it was really handy in structuring your code.
a
you could split the code up into different modules and only expose the
DB
f
Yeah I guess, have never understood the whole module thing though, seems complicated. So a server can consist of several different modules, is that common? I still want to build it all from one gradle command and all
u
Yeah you can split your gradle project into a multi-project and still build it with one gradle command
f
Damn that seems anoyying, I guess I have to read up on it. Seems like it will create a bunch of new problems that I really do not want to deal with. I am not writing a public api here, im just writing my own little app.
a
Then why is public an issue?
f
Its not an issue from a security standpoint, only from a structure standpoint. When I am in my controllers package working I don’t want to have access to my entire DB package, I only want to be able to access one class from it (
DB
) I just get so much junk in autocomplete as it is now. I was used to making stuff package private from java and I found it very useful and clean.
m
I see a couple options, but depends on team size, and preferences which one will work best. None are as convenient as package private, though. 1. Pull DB into its own module/library so then only public items will be visible 2. Configure IDE so that it ignores the files/packages you don’t want exposed. This could be facilitated by having a package with a unique name within the DB ‘module’. Of course this requires all team members to update their IDE configuration.