singleton


// dart singleton

main(List args) {
  var helper = DBHelper();
  helper = DBHelper();
  helper = DBHelper();
  helper = DBHelper();
  helper = DBHelper();
  helper = DBHelper();
  helper = DBHelper();
  helper = DBHelper();
  helper = DBHelper();
}

class DBHelper {
  static  DBHelper _helper;

  DBHelper._internal();

  factory DBHelper(){
    if( _helper == null){
      print('hahah');
      _helper =DBHelper._internal();
    }
    return _helper;
  }
}

 

你可能感兴趣的:(Dart)