y
05/16/2025, 5:55 AMsealed class
with a ton of stuff. I need to name it from outside (maybe an ill-advised API decision, let's pretend otherwise for now) however just about everything else (constructors, companion object methods, etc.) should be internal
.
is there a trick to reducing the number of times I use the word internal
in my source code?
for example, internal companion object
was useful here.Joffrey
05/16/2025, 7:30 AMYoussef Shoaib [MOD]
05/16/2025, 11:04 AMy
05/16/2025, 1:19 PMJoffrey
05/16/2025, 1:20 PMy
05/16/2025, 1:25 PMsealed class Foo {
internal class Bar1 : Foo()
internal class Bar2 : Foo()
}
class ThisThingIsPublic(foo: Foo)
and I would like to avoid having to write internal
everywhere. so my understanding of your suggestion was making Foo
internal and then adding a public FooInterface
Joffrey
05/16/2025, 1:29 PMinternal
by default.
I was just puzzled by the "namespace" aspect. If Foo
doesn't have any state and is just for namespace, then it could itself be an interface (independently of the idea of splitting the public interface).y
05/16/2025, 1:34 PMFoo
? anyway, I understand. thanks.Joffrey
05/16/2025, 1:35 PMsealed class
. It's really just nitpicking on a detail here. I always suggest to replace sealed class
with sealed interface
if we're not using state (or other class-only capabilities), just like I would suggest using val
instead of var
if we're not reassigning the variable.