|
|
|
|
|
by generateui
5145 days ago
|
|
There does not need to be any knowledge of _any_ class. A factory method _still_ needs a class instance, you don't need them with factory constructors. A classical, say Java or C# way will still need coupling to such a class. In dart, there is real decoupling going on. |
|
Uh no it does not, it just needs a class. Unless what you mean by "a class instance" is "a class object". A factory method is a classmethod, not an instancemethod.
A factory method and a "factory constructor" need exactly the same thing: the class object.
> In dart, there is real decoupling going on.
In dart, there's mostly a bloody mess of 4 different constructors when all you need is a constructor and an initializer, as done in e.g. Ruby or Python. And these can be "regular" methods (respectively on the class and on the instance).
Conversely, you can also have an "overridden" constructor as in Javascript: an instance is built, the constructor function is called using the instance as its context, and if the constructor returns something that something is returned by `new` in stead of the original object.