inheritance use case code example

Example: case class inheritance

/* The preferred way of avoiding case class inheritance without 
   code duplication is somewhat obvious: create a common (abstract) 
   base class: */

abstract class Person {
  def name: String
  def age: Int
  // address and other properties
  // methods (ideally only accessors since it is a case class)
}

case class Employer(val name: String, val age: Int, val taxno: Int)
    extends Person

case class Employee(val name: String, val age: Int, val salary: Int)
    extends Person