See a thorough discussion of the Smart Constructor Pattern here
This project uses two implementations for the Smart Constructor pattern in Scala.
- The weird (but useful)
sealed abstract case class Foo()
Rob Norris (@tpolecat in github, twitter), a very well known typelevel contributor, explains it very nicely in this gist. This approach has the benefit that does not require compiler plugins.
- Using the
@data
annotation (requires scala macros)
@data(copy=false, apply=false)
class Foo()