Reputation: 125
In Java I used to put classes inside packages with long informative names by template domain.company.project.module.ets
and used to names like:
But in the sources of akka and sbt projects there are a lot of classes inside packages with simple names:
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?
Upvotes: 1
Views: 635
Reputation: 11522
Hi I will reccomend you to read chater seven of scala for the imatient is free available here: http://typesafe.com/resources/free-books.
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.
Upvotes: 3