Object Oriented Concepts – Case Classes

As part of this topic, we will cover Case Classes in Scala

Case Class

  • Case classes can be pattern matched
  • Case classes automatically define hashcode and equals
  • Case classes automatically define getter methods for the constructor arguments(if we use var in the argument).

Example

case class Order(var orderId:Int,var orderDate:String,var orderCustomerId:Int,var orderStatus:String)
{
 println("I am inside Order Constructor")
 override def toString = "Order("+ orderId + "," + orderDate + "," + orderCustomerId + "," + orderStatus +")"
}

Object Creation

val order = Order(1, "2013-10-01 00:00:00.000", 100,"COMPLETE")

Share this post