这两个类的实现有什么区别?

我是编程和dart lang的初学者。我有一个关于如何编写与Flutter和Firestore相关的数据库服务的类的问题。

// what is the difference this
class DbService {
  final Firestore _db;
  DbService() : _db = Firestore.instance;

  Future<Querysnapshot> getDataCollection(String id) {
    return _db.collection(id).getDocuments();
  }
}
// and this
class DbService {
  final Firestore _db = Firestore.instance;

  Future<Querysnapshot> getDataCollection(String id) {
    return _db.collection(id).getDocuments();
  }
}


   // when use this class
_dbService = DbService();

什么是最佳做法?还是应该使用单例实例化此类?任何意见或帮助,表示赞赏。

woshijxsd0001 回答:这两个类的实现有什么区别?

它们在计算机上是相同的,但是它们给我的印象是不同的。

第二个很明显,其中第一个告诉我该构造函数曾经取值,或者可能在将来的版本中取值。

本文链接:https://www.f2er.com/3126676.html

大家都在问