What is best practice in terms of multiple classes...
# getting-started
h
What is best practice in terms of multiple classes in a single file? For example if I have an interface and a (currently) single implementation, I like the idea of keeping them together in a single file, but then sometimes feel I should do how I would in Java and split it into two.
e
Official coding conventions has a great paragraph about that:
Placing multiple declarations (classes, top-level functions or properties) in the same Kotlin source file is encouraged as long as these declarations are closely related to each other semantically and the file size remains reasonable (not exceeding a few hundred lines).
You can read the whole conventions here: https://kotlinlang.org/docs/reference/coding-conventions.html
🤩 1
h
Brilliant. Thanks a lot. I should probably read that a couple of times! 🙂
238 Views