/// 构造方法学习
class Cat {
  String name;
  String _color;

  // 构造方法
  Cat(this.name);

  // 命名构造方法
  Cat.copy(this.name);

  @override
  String toString() {
    return name;
  }
}

class BigCat extends Cat{
  String age;

  // 冒号后面的是初始化列表
  BigCat(String name,String age) : age = age + "岁", super(name);

  // 命名工厂构造方法
  factory BigCat.big(String name,String age){
    name = "我叫$name";
    return BigCat(name, age);
  }

  @override
  String toString() {
    return "$name   $age";
  }
}

class Logger{
  static Logger _cache;
  factory Logger(){
    if(_cache == null){
       _cache = Logger._internal();
    }
    return _cache;
  }
  Logger._internal();

  void log(String msg){
    print("sinki: $msg");
  }
}

class Dog{
  String name;
  String age;
  
  void play(){
    List list = [];
    list[0]=1;
    list[1]=0;
    list[2]="";
    list[3]=null;

    // 空判断
    if([0,"",null].contains(list[2])){
      mLog("list[2] is empty");
    }

    Cat redCat = Cat.copy("红猫");
    Cat blueCat = BigCat("蓝猫","123");
    Cat cat ;
    Logger().log(redCat.toString());
    Logger().log(blueCat.toString());
    Logger().log(cat?.toString()??"空对象");
    mLog(cat?.name);
  }
}

class Zom extends Cat with Dog{
  Zom(String name) : super(name);

}

void mLog(String msg){
  Logger().log(msg);
}