St.Antario
St.Antario

Reputation: 27425

Declaring two classes in the same compilation unit

I'm pretty new to Scala and would like to ask about conventions. I have the following classes:

case class Cltn(msgs: Seq[Msg])
case class Msg(value: Int)

Is it common to define this classes in the same compilation unit? Or this is not conventional and we should define them in different ones? I came from Java that's why I ask about this.

If we can define them in the same compilation unit, can we choose the name of this unit that differs from Cltn and Msg, or this is not conventional? Like Parameters.scala

Upvotes: 1

Views: 240

Answers (1)

OlivierBlanvillain
OlivierBlanvillain

Reputation: 7768

Grouping multiple (case) classes per files in idiomatic in Scala. It's also very common to have them extend a common sealed trait, in which case everything will have to be defined together.

As for naming conventions, I've seen two different approaches used regularly:

  • Name the file with the name of most important class in contains (CamelCase)

  • Use a lower case name of the logical concept grouping these things together.

In your case, it looks like the second option would fit better, I would go for parameters.scala!

Upvotes: 1

Related Questions