Skip to content

Instantly share code, notes, and snippets.

@nddrylliog
Created August 18, 2010 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nddrylliog/acdcae497a8de51117ac to your computer and use it in GitHub Desktop.
Save nddrylliog/acdcae497a8de51117ac to your computer and use it in GitHub Desktop.
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