Skip to content

Instantly share code, notes, and snippets.

@AAQ-AND-DEV
Last active March 24, 2019 20:23

Revisions

  1. AAQ-AND-DEV revised this gist Mar 24, 2019. 1 changed file with 41 additions and 11 deletions.
    52 changes: 41 additions & 11 deletions main.dart
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,45 @@
    class Cat{
    //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 kind;
    Cat(){}
    Cat.fromInfo(String name, String lastName, String color, int kind){
    this.name = name;
    this.lastName = lastName;
    this.color = color;
    this.kind = kind;
    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);

    String meow(){
    @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(){

    @@ -32,6 +57,11 @@ void main(){
    print(yourAge(name, lastName, 47));
    print(yourAge(name, lastName));

    var willie = new Cat.fromInfo(name, lastName, "black", 1);
    print("${willie.name} says ${willie.meow()}");
    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();
    }
  2. AAQ-AND-DEV created this gist Mar 24, 2019.
    37 changes: 37 additions & 0 deletions main.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    class Cat{
    String name;
    String lastName;
    String color;
    int kind;
    Cat(){}
    Cat.fromInfo(String name, String lastName, String color, int kind){
    this.name = name;
    this.lastName = lastName;
    this.color = color;
    this.kind = kind;
    }

    String meow(){
    return 'meow';
    }

    }
    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", 1);
    print("${willie.name} says ${willie.meow()}");
    }