gpt4 book ai didi

dart - extends Object with Observable 和 extends Observable 有什么区别

转载 作者:行者123 更新时间:2023-12-04 17:49:47 28 4
gpt4 key购买 nike

使用 Observable 扩展 Object 和应用于以下类的扩展 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 :

When you extend "Object" with a mixin the first mixin can always take the place of "Object".



唯一的区别在于类层次结构( 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'
}

关于dart - extends Object with Observable 和 extends Observable 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19764838/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com