-
-
Save nddrylliog/acdcae497a8de51117ac 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
Printable: interface { | |
// this one has to be implemented | |
toString: func -> String | |
// this one has a default impl. | |
println: func { | |
toString() println() | |
} | |
// this one has a default impl too | |
prettyPrint: func { | |
"Charly says: " print() | |
println() | |
} | |
} | |
Number: class implements Printable { | |
value: Int | |
init: func (=value) {} | |
// we're required to implement this one, so let's implementt it | |
toString: func -> String { value toString() } | |
// but we override this one | |
prettyPrintln: func { | |
"<< %s >>!" printfln(toString()) | |
} | |
} | |
n := Number new(42) | |
n toString() println() | |
n println() | |
n prettyPrintln() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment