https://kotlinlang.org logo
#getting-started
Title
# getting-started
e

elect

10/20/2023, 6:53 AM
is there a workaround to have an inner class with its body defined in some other file in order to not bloat the parent class itself?
y

Youssef Shoaib [MOD]

10/20/2023, 7:02 AM
You could use a
context(Foo) class Bar
+ a
fun Foo.Bar(unit: Unit = Unit) = Bar()
pity 😞
I'll just pass an instance of the parent class in the constructor then
v

Vishnu Shrikar

10/20/2023, 3:42 PM
What is the reason for inner class use? Maybe there is a pattern that could do something similar with less bloat? if you want the parent class, perhaps you can use inheritance and extend the class?
e

elect

10/20/2023, 5:15 PM
I'm parsing some format and the inner classes represent groups of logical properties (tens), a couple of these are so much more important than the others that have to be available directly on the parent class. However, they do need some preprocessing
v

Vishnu Shrikar

10/20/2023, 5:20 PM
Could you define them in another file and just pass them in? If you have koin you can even inject properties directly
e

elect

10/20/2023, 6:47 PM
yes, that's what I did
🙌 1