Last active
March 24, 2019 20:23
-
-
Save AAQ-AND-DEV/3a24d91446ffae7da0c1eceabaa7b17c to your computer and use it in GitHub Desktop.
basic class w/named ctor
This file contains hidden or 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
//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