Case object

sealed trait Topping
case object Cheese extends Topping
case object Pepperoni extends Topping
case object Sausage extends Topping
case object Mushrooms extends Topping
case object Onions extends Topping

sealed trait CrustSize
case object SmallCrustSize extends CrustSize
case object MediumCrustSize extends CrustSize
case object LargeCrustSize extends CrustSize

sealed trait CrustType
case object RegularCrustType extends CrustType
case object ThinCrustType extends CrustType
case object ThickCrustType extends CrustType
case class Pizza (
    crustSize: CrustSize,
    crustType: CrustType,
    toppings: Seq[Topping]
)

Is like an object, but just like a case class has more features than a regular class, a case object has more features than a regular object.

It’s serializable. It has a default hashCode implementation. It has an improved toString implementation.

Case object → belongs to → Objects.

Case object — Structure map

Clickable & Draggable!

Case object — Related pages: