I find it quite weird that classes ignore the extends part when used as mixin.Maybe I'm just a bit unfamiliar with this idea.
When the class used as mixin accesses members of its superclass, are these members then expected to be present in the class (or superclass of) where the mixin is applied to instead?
On Thu, Aug 13, 2015 at 11:31 AM, Günter Zöchbauer <gzo...@gmail.com> wrote:I find it quite weird that classes ignore the extends part when used as mixin.Maybe I'm just a bit unfamiliar with this idea.
The key misunderstanding seems to be that people think they are mixing in a class. What you actually mix-in is a mixin. The mixin is what a class adds to its superclass - intuitively, the stuff between the curly braces in the class declaration.A mixin is really a very special kind of function, one that takes a superclass S and returns a subclass of S. A class is always associated with a mixin. You could think of class Foo extends Bar { ...} asFooMixin(S) { return class extends S {...}} // illegal in Dart of coursealong withvar Foo = FooMixin(Bar);The with notation is really a syntax for applying these mixin functions.class C extends S with M1 with M2is reallyclass C extends (M2.mixin(M1.mixin(S)))where M1 and M2 are classes, and X.mixin denotes the mixin function implicitly induced by class X. Having such a special notation for mixins may or may not help but is certainly more verbose, which nobody likes.
class M1Base {}class M1 extends M1Base {}class M2Base {}class M2 extends M2Base {}class C extends S with M1, M2C > M2 M2Base M1 M1Base S
class C extends (M2.mixin(M2Base.mixin(M1.mixin(M1Base.mixin(S)))))
class C extends (M2.supercompose(M1.supercompose(S)))
Once you understand the semantics, you realize that mixing in the entire inheritance chain only makes sense via mixin composition, just as applying a series of functions must be made explicit via function composition.
In the end, software engineering isn't always trivial. Sometimes one has to learn new things.
Supporting both variations seems like too much. Supporting the proposal as defined is more flexible than the alternative described in this thread.
--Cheers, Gilad
I missed the part on relaxing restrictions on mixin classes that triggered this, so if I'm off base, then feel free to disregard.What value is there to mixing in a class that has a non-Object superclass?
class Vehicle {
Engine engine;
start() { engine.start(); }
}
class Car extends Vehicle {
turnKey() { start(); }
}
class Driver extends Person with Car {}
var driver = new Driver()..turnKey();
One never mixies in a class. One mixes in a mixin, derived from a class. If you apply that mixin to a superclass with the suitable properties, it will work fine.
In your example, if Person had a start method (I know that's far fetched) things would work. Somewhat more realistically, if you had a different implementation of Vehicle, you could apply Car to it. More realistically still, people have wanted to compose chains of UI widgets in Polymer separate from their original inheritance chain.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
The feature looks cute and ingenious.If my understanding is correct, then in the context of:class M extends I {...}class C with M {...}the first definition (of class M) should really read like this:class M that_can_be_applied_as_mixin_to_any_class_that_implements I {...}
If this interpretation is true, then the the entire reason why the idea looks so ingenious is:Verb "extends" in the definition of M gets re-interpreted as the whole phrasecan_be_applied_as_mixin_to_any_class_that_implements. Cute!!!Now my question is: are we really so short of words that we have to load the word "extends" with second, fairly non-obvious, meaning?What harm would it make if language just defined a new keyword? This can be done in many ways, e.g. (first one that comes to mind)mixin class M for I {...} // explicitly says the class was designed as mixin; clearly specifies condition of use.
an advanced mixin paradigm would do everything inheritance does.
(provided we correctly handle super call which I'm not sure how)
Always python mro for super..
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Does anybody feel that mixin might be a more fundamental concept than inheritance? Or it's only me?