Case Class naming convention

Posted by KChaloux on Programmers See other posts from Programmers or by KChaloux
Published on 2012-08-29T19:39:16Z Indexed on 2012/08/29 21:50 UTC
Read the original article Hit count: 396

Filed under:
|
|

In my recent adventures in Scala, I've found case classes to be a really nice alternative to enums when I need to include a bit of logic or several values with them. I often find myself writing structures that look like this, however:

object Foo{
  case class Foo(name: String, value: Int, other: Double)

  val BAR = Foo("bar", 1, 1.0)
  val BAZ = Foo("baz", 2, 1.5)
  val QUUX = Foo("quux", 3, 1.75)
}

I'm primarily worried here about the naming of the object and the case class. Since they're the same thing, I end up with Foo.Foo to get to the inner class. Would it be wise to name the case class something along the lines of FooCase instead? I'm not sure if the potential ambiguity might mess with the type system if I have to do anything with subtypes or inheritance.

© Programmers or respective owner

Related posts about naming

Related posts about coding-standards