on
[Flutter] Dart. Simple Mixin Example
[Flutter] Dart. Simple Mixin Example
728x90
Mixin is like Implement.
If you impletemnt Interfaces in java or kotlin, you can use Mixin in Dart.
void main() { Publisher().postComment(); Publisher().publishArticle(); Admin().postComment(); Admin().publishArticle(); Admin().deleteComment(); } class User{ void postComment(){ print('posted comment'); } } class Moderator extends User{ void deleteComment(){ print('comment deleted'); } } class Publisher extends User with CanPublishArticle{ } class Admin extends Moderator with CanPublishArticle { } mixin CanPublishArticle{ void publishArticle(){ print("article published"); } }
Console
posted comment article published posted comment article published comment deleted
320x100
from http://jinhan38.tistory.com/103 by ccl(A) rewrite - 2021-11-10 01:01:41