Answers for "is inheritance possible in use case"

0

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
Posted by: Guest on March-31-2021

Code answers related to "is inheritance possible in use case"

Code answers related to "Scala"

Browse Popular Code Answers by Language