Links
- Why Dart does not inherit constructor?
- inheritance - How do I call a super constructor in Dart?
-
Redirecting/Forwarding Constructors (search in ch02)
class Point { num x; num y; Point(this.x, this.y); // The main constructor for this class. // A redirecting constructor’s body is empty, with the constructor call appearing after a colon (:). Point.alongXAxis(num x) : this(x, 0); // Delegates to the main constructor. }
-
Redirecting Factory Constructors
class Foo { Foo(int a, int b) { … } Foo.named(int c, int d) { … } } class Bar extends Foo { Bar(int a, int b) : super(a,b); } class Baz extends Foo { Baz(int c, int d) : super.named(c,d); } // factory TemplateCache() = LruCache<String, HttpResponse>;
-
class Foo { f() { print("foo"); } } class Bar extends Foo { f() { super.f(); print("bar"); } }