Paul--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
The default constructor for B calls the default *generative* constructor for A, which doesn't exist. Put another way, if we allowed this, you'd have an infinite loop, as the B constructor would call the A factory that calls the B constructor ...
I would suggest that B implement A instead.
So if A implemented some methods (say foo), the right way to do it is:abstract class A {factory A() => new B();}class _A implements A {foo() => 42;}class B extends _A {}main() {new B();}Is that right? (Modulo bad choice of name of _A.)
On Tue, Sep 18, 2012 at 10:45 PM, Gilad Bracha <gbr...@google.com> wrote:
The default constructor for B calls the default *generative* constructor for A, which doesn't exist. Put another way, if we allowed this, you'd have an infinite loop, as the B constructor would call the A factory that calls the B constructor ...Ok, I had guessed something along these lines and had tried to add a generative constructor A() that does nothing but of course it clashes with the factory constructor.I would suggest that B implement A instead.
So if A implemented some methods (say foo), the right way to do it is:abstract class A {factory A() => new B();}class _A implements A {foo() => 42;}class B extends _A {}main() {new B();}Is that right? (Modulo bad choice of name of _A.)
abstract class A {A();
factory A() => new B();
foo() => 42;}
class B extends A {}main() {new B();}
abstract class A {A._();
factory A() => new B();
foo() => 42;}class B extends A {B() : super._();}main() {new B();}
On Tue, Sep 18, 2012 at 1:52 PM, Paul Brauner <po...@google.com> wrote:
On Tue, Sep 18, 2012 at 10:45 PM, Gilad Bracha <gbr...@google.com> wrote:
The default constructor for B calls the default *generative* constructor for A, which doesn't exist. Put another way, if we allowed this, you'd have an infinite loop, as the B constructor would call the A factory that calls the B constructor ...Ok, I had guessed something along these lines and had tried to add a generative constructor A() that does nothing but of course it clashes with the factory constructor.I would suggest that B implement A instead.
So if A implemented some methods (say foo), the right way to do it is:abstract class A {factory A() => new B();}class _A implements A {foo() => 42;}class B extends _A {}main() {new B();}Is that right? (Modulo bad choice of name of _A.)The other option, if you don't want to make an extra _A class, is to give A a constructor:abstract class A {A();factory A() => new B();foo() => 42;}
class B extends A {}main() {new B();}
If you don't want people to call it, you can make it private:abstract class A {A._();factory A() => new B();foo() => 42;}class B extends A {B() : super._();}main() {new B();}