Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between extends Object with Observable and extends Observable

Tags:

dart

What is the difference between extends Object with Observable and extends Observable as applied to the class below.

The result is the same when the application is run.

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;
  }
}
like image 758
st_clair_clarke Avatar asked Nov 04 '13 09:11

st_clair_clarke


1 Answers

There no difference in the behaviour between this two declarations.

Here's a quote from Florian Loitsch :

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

The only little difference is in class hierarchy (superclass are not the same) :

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'
}
like image 95
Alexandre Ardhuin Avatar answered Nov 13 '22 23:11

Alexandre Ardhuin