Is it possible to specify declaration's visibility...
# getting-started
p
Is it possible to specify declaration's visibility as union of PROTECTED and INTERNAL? So it can be accessed from the same module or from any subclass regardless of subclass's module.
j
I don't think this is possible, but you could (as a workaround) declare another member with the other visibility and implement it by just delegating to the other
p
Yes. I'm woring around like you wrote, but it will be nicer to avoid it.
s
you could create arteficial visibility ranges with Konsist. Then it's not the compiler asserting that everything is correct but unit tests: https://kotlinconf.com/2024/talks/569136/ https://docs.konsist.lemonappdev.com/
d
I’d be curious to know what kind of class hierarchy would need this. It sounds like it doesn’t conform with the SOLID principles.
1
p
My pattern is 'manager' that operates objects. All object manipulations are allowed only by manager. And also objects can have class hierarhy extending their behaviour by overriding those functions. Both manager and root object class located in same module, while subclasses can be defined in other modules.
d
That makes sense. I would probably look into using a Strategy Pattern instead of overriding functions. Create interfaces for the pieces that can be atomically overridden, and create
internal val
for each of those interfaces.
This follows "prefer composition over inheritance" idea.