How to structure your Scala application?

Click for: original source

Michał Matłoka wrote this piece about the application organization and structure in Scala. In Scala, one tends to see smaller libraries, which are quite flexible. That is why many things like application structure and life-cycle fully depend on developer.

The most important question is, how to keep order in your project? Initially, it may be solidly designed, but over time some mess may appear. How to avoid cycles between packages or enforce checks not allowing to use feature internal classes by another feature? There comes the ArchUnit with its DSL allowing to define all those checks in tests.

The article is split into:

  • Object creation style
  • Modules as traits
  • Modules as classes
  • Package organization
  • Tests
  • Maintaining order

Scala may give you more power but you have to be careful not to introduce mess in your project. You shouldn’t be afraid of using the good old new keyword for instantiating dependencies. And DI framework may not be really needed in your application. Enjoy!

[Read More]

Tags scala programming java oop functional-programming