dimanche 4 avril 2021

Is there any non-trivial application of the following pattern?

Consider the following code snippet. The field instance is lazily instantiated.

class Foo {
  static int counter = 0;
  late Foo instance = Foo();
  Foo() {
    print('${++counter}');
  }
}

void main() {
  Foo f = Foo();
  f.instance.instance.instance.instance.instance;
  print('end of program');
}

Question

Is there any non-trivial application of this pattern?

Aucun commentaire:

Enregistrer un commentaire