|
|
|
|
|
by generateui
5145 days ago
|
|
> A factory method is a classmethod, not an instancemethod. This completely depends on your implementation. It's possible to implement it as instance method, or static method. > Uh no it does not, it just needs a class. Whether it be a static factory method or an instance method, fact is you need a reference to an implementation (class). In dart, you can do List someListInstance = new List();
where List is an interface. There is none class needed in your consuming code, none. In C# or Java, this is impossible: You need _some_ class (whether it be a static method on it, or an instance method) to get a new instance of the interface.Named constructors felt very liberating when working with Dart. new List.from([instance1, instance1]);
delivers a lot of clarity, while offering the promised decoupling by the GoF:> Define an interface for creating an object, but let the classes which implement the interface decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses. |
|
It makes no sense, if you're doing that you've switched to full-blown factories (abstracts or builders), you're not using factory methods anymore.
> Whether it be a static factory method or an instance method, fact is you need a reference to an implementation (class). In dart, you can do
> List someListInstance = new List();
> where List is an interface. There is none class needed in your consuming code, none.
That's got nothing to do with factories, or interfaces.
> You need _some_ class (whether it be a static method on it, or an instance method) to get a new instance of the interface.
You always need a class, even in Dart there has to be a default List implementation of some sort which can be called (and has to be specified on the interface, it's not like you can even provide your own default implementation of a third party's interface). As to the calling code needing to know about that one concrete implementation:
Oh look at that, the calling code does not know anything about FooImpl.> Named constructors felt very liberating when working with Dart.
Yeah, that's so much more liberating than:
Wait, no it's not.