Dart 单例模式

class Service {
  // 工厂模式
  factory Service() =>_getInstance();
  static Service get instance => _getInstance();
  static Service _instance;
  Service._internal() {
    // 初始化
  }
  static Service _getInstance() {
    if (_instance == null) {
      _instance = new Service._internal();
    }
    return _instance;
  }
}

  

posted @ 2020-06-05 17:25  MJHelloWorld  阅读(1612)  评论(0编辑  收藏  举报