Is there a reason why using json_serializable I should use a factory constructor instead of a static method?
I would need to use a static method, but I'm wondering about the downsides
Is there a reason why using json_serializable I should use a factory constructor instead of a static method?
I would need to use a static method, but I'm wondering about the downsides
Using factory
has a purpose here:
it forces you to define
factory
counts as a constructor, so if you define at least one then there's no implicit constructor:
class Foo {
factory Foo.fromJson() {
return Foo(); // Doesn't compile
}
}
Which is opposed to:
class Foo {
static Foo.fromJson() {
return Foo(); // compiles
}
}