my Goal is to structure my code with this. The Idea is to outsource an inplementation to elsewhere, so that your main class is not so overloaded with way to much methods. Mixins seamed to be perfect for that! Example:
abstract class Animal {
String printAllPropeties();
}
class Elephant extends Animal {
Trunk trunk; // Trunk: some Datastructure
@override
String printAllPropeties() => trunk.toString();
}
class Bird extends Animal {
Wing wing; // Wing: some Datastrukture
@override
String printAllPropeties() => wing.toString();
}
But now I want to outsource printAllPropeties()
to a mixin for each class:
abstract class Animal {
String printAllPropeties();
}
class Elephant extends Animal with ElephantAllPropeties {
Trunk trunk; // Trunk: some Datastructure
}
mixin ElephantAllPropeties on Elephant {
@override
String printAllPropeties() => trunk.toString();
}
class Bird extends Animal with BirdAllPropeties {
Wing wing; // Wing: some Datastrukture
}
mixin BirdAllPropeties on Bird {
@override
String printAllPropeties() => wing.toString();
}
But this would not work like it is now, because the mixin would implement itself. So is there another way, or is it simply not possible, or possible with other methods??