Created
November 8, 2021 04:57
-
-
Save j-thepac/fa31bcd1ab228f9839f2e6fa5573d15d to your computer and use it in GitHub Desktop.
Scala Domain Model using Traits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Activities | |
case class PersonWalk(km:Float) extends Activities | |
case class PersonTalk(words:String) extends Activities | |
class CompanionPerson { | |
def perform(act:Activities)= { | |
act match{ | |
case PersonWalk(km) => println(km) | |
case PersonTalk(words) => println(words) | |
case _ =>print("Not defined") | |
} | |
}} | |
object CompanionTest extends App { | |
val person:CompanionPerson=new CompanionPerson() | |
person.perform(PersonTalk("hi")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment