How to package Scala code with the “curly braces” style

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 7.1, “How to package Scala code with the 'curly braces' style.”


You want to use a nested style package notation, similar to the namespace notation in C++ and C#.


Wrap one or more classes in a set of curly braces with a package name, as shown in this example:

Scala packaging and import examples

This article is a collection of Scala packaging and import examples. I created most of these examples when I was writing the Scala Cookbook. I share them here without much discussion, but for more examples and discussion, please check out the Cookbook.

Packages imported by default

By default, three packages are implicitly imported for you:

UML package diagram - application packaging alvin November 17, 2005 - 5:43pm

Question: I want to show how my application classes are segregated into packages. Is there a UML diagram for this?

Yes, you pretty much named it. A UML package diagram is good for demonstrating the packages (or packaging) in a software application, as well as the dependencies between packages.