FireFry FireFry -3 years ago 113
Scala Question

How to organize classes inside scala project?

In Java I used to put classes inside packages with long informative names by template
and used to names like:


  • org.hibernate.cache


But in the sources of akka and sbt projects there are a lot of classes inside packages with simple names:


  • sbt

And that's not all. There are many classes inside classes. And by classes I also mean objects and traits in all possible combinations. There are object inside traits, traits inside classes, etc. But the level of nesting is always 1 (or should I say 2?).

Obviously, there is another approach to class organization. I wonder if you can give me a tip of how to name packages in scala and when to put classes inside each other?

Answer Source

Hi I will reccomend you to read chater seven of scala for the imatient is free available here:

As a summary the keypoints, as sayed in the book:

- Packages nest just like inner classes.
- Package paths are not absolute.
- A chain x.y.z in a package clause leaves the intermediate packages x and x.y invisible.
- Package statements without braces at the top of the file extend to the entire file.
- A package object can hold functions and variables.
- Import statements can import packages, classes, and objects.
- Import statements can be anywhere.
- Import statements can rename and hide members.
- java.lang, scala, and Predef are always imported.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download