Skip to content

Instantly share code, notes, and snippets.

Created May 8, 2016 04:57
Show Gist options
  • Save anonymous/7eba042e173e82ec0ce3b64784e96a01 to your computer and use it in GitHub Desktop.
Save anonymous/7eba042e173e82ec0ce3b64784e96a01 to your computer and use it in GitHub Desktop.
Color
class Color {
String to_s() {
if(this is Red){
return "#FF0000";
}else if(this is Green) {
return "#00FF00";
}else if(this is Blue) {
return "#0000FF";
}else if(this is Rgb) {
return "rgb";
}else {
throw new Error();
}
}
}
class Red extends Color{}
class Green extends Color{}
class Blue extends Color{}
class Rgb extends Color {
num r;
num g;
num b;
Rgb(this.r,this.g,this.b);
}
void main() {
Color c = new Rgb(255,255,255);
print(c.to_s());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment