Created
February 9, 2010 04:01
-
-
Save chrislewis/298903 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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