Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Created February 9, 2010 04:01
Show Gist options
  • Save chrislewis/298903 to your computer and use it in GitHub Desktop.
Save chrislewis/298903 to your computer and use it in GitHub Desktop.
/**
* A simple look at ADT-style code in place of classical objects in Scala.
*
* import ADT.Person._
* val p = create("Chris", "Lewis")
* println(firstName(p))
*/
object ADT {
class Person private (private val firstName : String, private val lastName: String)
object Person {
def create(firstName: String, lastName: String) = new Person(firstName, lastName)
def firstName(p: Person) = p.firstName
def lastName(p: Person) = p.lastName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment