Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dartlang syntax to extend a class with a mixin?

Tags:

dart

Can somebody explain this dart syntax? Is this documented somewhere?

abstract class FixedLengthListBase<E> =
    ListBase<E> with FixedLengthListMixin<E>;
like image 693
markovuksanovic Avatar asked Feb 04 '14 12:02

markovuksanovic


2 Answers

This is the syntax for declaring a named mixin application. It is introduced in the "Mixins in Dart" article.

They are defined by a special form of class declaration that gives them a name and declares them equal to an application of a mixin to a superclass, given via a with clause.

This is (almost) the same as writing

abstract class FixedLengthListBase<E> extends
    ListBase<E> with FixedLengthListMixin<E>{}

The technical difference is that in this case FixedLengthListBase is not a mixin application itself, but an abstract subclass of the implicit, unnamed mixin application ListBase<E> with FixedLengthListMixin<E>

like image 153
MarioP Avatar answered Sep 20 '22 02:09

MarioP


This is a form of mixin application class declaration.

classDefinition:
  metadata abstract? class mixinApplicationClass

mixinApplicationClass:
  identifier typeParameters? '='  mixinApplication ';'

The mixin application may be used to extend a class;

alternately, a class may be defined as a mixin application as described in this section.

mixinApplicationClass:
  identifier typeParameters? '='  mixinApplication ';'
abstract class FixedLengthListBase<E> =
    ListBase<E> with FixedLengthListMixin<E>;

https://www.dartlang.org/docs/spec/latest/dart-language-specification.html#h.trk07h8vrppk

like image 29
mezoni Avatar answered Sep 19 '22 02:09

mezoni