I have some misunderstanding in what cases I should use case class or regular class following by best practices. I have already read about differences of both classes but ca
Case Classes are normal classes with syntactic sugar. So there is no real big difference, you can do everything with a case class you can do with a class and vice versa.
Case classes just save you a lot of boiler plate code to write.
Perfect fit, as the name suggests, is the use of case classes in pattern matching with case
.
case class MyCase(name: String, age: Int)
data : List[MyCase] = ...
data foreach {
case MyCase(_, age) if age > 21 => println("old enough")
case MyCase("fred", _ ) => println("Got you")
case _ => ...
}