具有Observable的extended Object和应用于以下类的extended Observable之间有什么区别?

运行该应用程序时,结果是相同的。

library models;

import 'package:polymer/polymer.dart';

class Person extends Object with Observable {
  @observable String name;
  @observable bool signedAgreement = false;

  Person();

  Person.from(Person other) {
    name = other.name;
    signedAgreement = other.signedAgreement;
  }

  blank() {
    name = '';
    signedAgreement = false;
  }
}


library models;

import 'package:polymer/polymer.dart';

class Person extends Observable {
  @observable String name;
  @observable bool signedAgreement = false;

  Person();

  Person.from(Person other) {
    name = other.name;
    signedAgreement = other.signedAgreement;
  }

  blank() {
    name = '';
    signedAgreement = false;
  }
}

最佳答案

这两个声明之间的行为没有差异。

这是a quote from Florian Loitsch:



唯一的区别是在类层次结构中(superclass不同):

import 'dart:mirrors';

abstract class Mixin {}
class A extends Mixin {}
class B extends Object with Mixin {}

main() {
  print(reflectClass(A).superclass);
  // => ClassMirror on 'Mixin'

  print(reflectClass(A).superclass.superclass);
  // => ClassMirror on 'Object'

  print(reflectClass(B).superclass);
  // => ClassMirror on 'dart.core.Object with .Mixin'

  print(reflectClass(B).superclass.superclass);
  // => ClassMirror on 'Object'
}

07-26 02:36