St.Antario
St.Antario

Reputation: 27455

Package object for type definintions

I'm still new to Scala and have a question about package object.

I have a package com.pack.age.command which contains the following trait:

trait Command

case object Help extends Command

Now, I would like to define a function to process commands:

type CommandArgument = scala.Any
type CommandProcessor = Command => CommandArgument => Unit

I tend to put these type definitions into a package object.

package object command {
  type CommandArgument = scala.Any
  type CommandProcessor = Command => CommandArgument => Unit
}

The reason is that these types are same for all commands so it looks pretty much logically to me.

But is it common to do like that in Scala?

Upvotes: 0

Views: 56

Answers (1)

Yaneeve
Yaneeve

Reputation: 4779

Though I personally like type aliases, these things, I find are very subjective where some community members use them more than others.

Take a look at the following recommendations:

Twitter's Effective Scala style guide

Upvotes: 1

Related Questions