簡體   English   中英

Dart - 摘要 class 有一個工廠和它的孩子

[英]Dart - abstract class with a factory and its children

我的 flutter 應用程序中有兩個 class:

 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"],
     );
 }

我可以為這兩個添加父 class 嗎? 或多或少像這樣

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

dart有可能嗎? 或其他方式-使用mixin?

構造函數不是繼承的,所以可能不會。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM