FetFrumos
FetFrumos

Reputation: 5944

Dart - abstract class with a factory and its children

I have two class in my flutter app:

 class ChildrenA{
     ....
     factory ChildrenA.fromJson(Map<String, dynamic> json) => ChildrenA(
            x: json["x"],
            y: json["y"],
     );
 }

class ChildrenB{
     ....
     factory ChildrenA.fromJson(Map<String, dynamic> json) => ChildrenB(
            x1: json["x1"],
            y2: json["y2"],
     );
 }

Can I add a parent class for these two? more or less like this

   abstract class Parent{
     factory Parent.fromJson(Map<String,dynamic> json);
   }

is it possible in dart? or other ways - using mixin?

Upvotes: 1

Views: 222

Answers (1)

Randal Schwartz
Randal Schwartz

Reputation: 44081

Constructors are not inherited, so probably no.

Upvotes: 1

Related Questions