Kotlin Data Class packaging [closed]

坚强是说给别人听的谎言 提交于 2019-12-01 17:30:21

The coding style conventions give quite explicit guidance on this:

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).

The book Kotlin in Action says about source code layout (chapter 2.2.3, page 27):

In Kotlin, you can put multiple classes in the same file and choose any name for that file.

...

In most cases, however, it's still good practice to follow Java's directory layout and to organize files into directories according to the package structure. Sticking to that structure is especially important in projects where Kotlin is mixed with Java.

...

But you shouldn't hesitate to pull multiple classes into the same file, especially if the classes are small (and in Kotlin, they often are).

So to answer your questions: it depends :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!