Skip to content

Instantly share code, notes, and snippets.

@AAQ-AND-DEV
Last active March 24, 2019 20:23
Show Gist options
  • Save AAQ-AND-DEV/3a24d91446ffae7da0c1eceabaa7b17c to your computer and use it in GitHub Desktop.
Save AAQ-AND-DEV/3a24d91446ffae7da0c1eceabaa7b17c to your computer and use it in GitHub Desktop.
basic class w/named ctor
//dart does not do interfaces, but rather all classes
//seem to be able to be implemented
abstract class IsFerocious {
void intimidate();
String whatTheFearfulSay();
}
class Animal{
String name;
String lastName;
String color;
int weight;
Animal(){}
Animal.create(this.name){}
Animal.fromInfo(this.name, this.lastName, this.color, this.weight){}
String sayHello(){
return 'grunt';
}
}
class Cat extends Animal implements IsFerocious{
Cat.create(String name): super.create(name){
print(".create ctor used");
}
Cat.fromInfo(String name, String lastName, String color, int weight) : super.fromInfo(name, lastName, color, weight);
@override
String sayHello() {
return 'meow';
}
@override
void intimidate(){
print("${this.name} hisses");
}
@override
String whatTheFearfulSay(){
print("oh no! the cat is hissing. I'm so scared");
}
}
void main(){
var name = "willis";
var lastName = "busterino";
String yourAge(String name, String last, [int age]){
var res = "$name $last";
if (age != null){
res += " is $age";
}
return res;
}
print(yourAge(name, lastName, 47));
print(yourAge(name, lastName));
var willie = new Cat.fromInfo(name, lastName, "black", 5);
print("${willie.name} says ${willie.sayHello()}");
var jeo = new Cat.create("jeordie");
print("${jeo.name} says ${jeo.sayHello()}");
willie.intimidate();
willie.whatTheFearfulSay();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment