19 Case classes to structure your data

 

After reading this lesson, you’ll be able to

  • Represent immutable structured data using case classes
  • Decide when to use case objects rather than regular objects
  • Use case classes together with pattern matching

In the previous unit, you mastered how to create a simple HTTP server. In this lesson, you’ll discover an essential tool in your Scala’s toolbox called case class. When coding, dealing with data is a fundamental and recurring task. A case class provides a convenient and efficient way to represent your data in an immutable way that allows you to share data between multiple threads safely. Being able to express data efficiently and conveniently is essential to make sure our program works correctly. You’ll also learn about case objects and how they can be useful when serialization is involved. Finally, you’ll see how pattern matching provides dedicated support for case classes thanks to the unapply function. In the capstone, you’ll use case classes and case objects to represent the core elements of the game “Paper, Rock, Scissors, Lizard, Spock!”

19.1 Case class

 
 
 
 

19.2 Pattern matching and case classes

 
 

19.3 Case object

 

Summary

 

Answers to quick checks

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest