I'm writing a program in which I'm using the factory pattern. I have an interface called AssetFundCalculator and a class named AssetFundCalculatorImpl which implements the interface.
The AssetFundValidator class validates some inputs, and is able to instantiate a valid AssetFundCalculatorImpl.
I'd like if the rest of the program would only know about the interface, and not about the AssetFundCalculatorImpl, so that only the AssetFundValidator could instantiate it.
My package structure is looking like this:
In Java, I would give package visibility modifier to the AssetFundCalculatorImpl class, or it's constructor, and it would solve the issue, but in Kotlin, there is no package visibility modifier.
Is there a solution to this? I don't want to put this code to a separately compiled module, so the internal modifier is not going to work.
You can put AssetFundValidator
and AssetFundCalculatorImpl
into the same file and mark AssetFundCalculatorImpl
as private
. In that case it will only be accessible to code in the same file, including AssertFundValidator
, but not to any code in other parts of the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With