We learned about
class in a previous SKB, today we are going to learn about
case class. They serve the same purpose which is to provide a blueprint to create
objects. But case class provides a lot of build-in advantages.
As a start, notice how the case class is being instantiated, and how the fields are being accessed.
Did you notice that we do not need
new to create the instance of the
And did you notice that we do not need a function to access any of the fields?
case class provide build-in things, let’s go over them:
newkeyword. Note that
classwill not need
neweither in Scala 3. To understand how this is done, remember the words
Companion Object, we are going to come back to it later.
case class, the field are
public( we are going to talk about
visibilitylater ) by default. So you can access their values without the need to a method that will return it for you.
Serializationfor later SKBs.