myfreax / myfreax-blog-issue

myfreax blog feedback
2 stars 0 forks source link

understand-darts-mixins/ #3

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

理解Dart的Mixin

https://www.myfreax.com/understand-darts-mixins/

RainFool commented 3 years ago

Mixmin看起来是覆盖关系 AB执行结果是B,因为AB最后with了B; BA执行结果是A,因为最后with了A

个人理解有点像Java里的接口,但是带了自己的实现,如果此时AB又复写getMessage方法,那执行结果将是AB复写的结果

myfreax commented 3 years ago

@RainFool 差不多是这个理解,因为dart不能多继承,Mixmin就类似多继承,方法可以被重写,返回值,参数都跟Mixmin 类一致,否则报错