Scala application structure

前端 未结 2 1272
野趣味
野趣味 2020-12-22 15:55

I am learning Scala now and I want to write some silly little app like a console Twitter client, or whatever. The question is, how to structure application on disk and logic

2条回答
  •  有刺的猬
    2020-12-22 16:40

    Scala supports and encourages the package structure of Java /JVM and pretty much the same recommendation apply:

    • mirror the package structure in the directory structure. This isn't necessary in Scala, but it helps to find your way around
    • use your inverse domain as a package prefix. For me that means everything starts with de.schauderhaft. Use something that makes sense for you, if you don't have you own domain
    • only put top level classes in one file if they are small and closely related. Otherwise stick with one class/object per file. Exceptions: companion objects go in the same file as the class. Implementations of a sealed class go into the same file.
    • if you app grows you might want to have something like layers and modules and mirror those in the package structure, so you might have a package structure like this: ....
    • don't have cyclic dependencies on a package, module or layer level

提交回复
热议问题