Mixin是一种类,这种类包含了其他类要使用的特性方法,但不必充当其他类的父类。Matlab无疑是支持多继承的。我们可以利用 Matlab 的这种特性,实现一种叫做 Mixin 的类。MixIn的目的就是给一个类增加多个功能,这样,在设计类的时候,我们优先考虑通过多重继承来组合多个MixIn的功能,而不是设计多层次的复杂的继承关系。(见https://blog.csdn.net/qq_31156277/article/details/80659537)

Automobile.m

classdef Automobile < handle
methods(Abstract)
dispAutomobile(~);
end
end

Car.m

classdef Car < Automobile
methods
function dispAutomobile(~)
disp("Car");
end
end
end

Bus.m

classdef Bus < Automobile
methods
function dispAutomobile(~)
disp("Bus");
end
end
end

Color.m (混入类Mixin)

classdef Color < handle
methods(Abstract)
dispColor(~);
end
end

Red.m(混入类Mixin)

classdef Red < Color
methods
function dispColor(~)
disp("Red");
end
end
end

Blue.m (混入类Mixin)

classdef Blue < Color
methods
function dispColor(~)
disp("Blue");
end
end
end

RedCar.m

classdef RedCar < Car & Red
methods
function dispThis(obj)
disp("RedCar is:");
obj.dispColor();
obj.dispAutomobile();
end
end
end

BlueBus.m

classdef BlueBus < Bus & Blue
methods
function dispThis(obj)
disp("BlueBus is:");
obj.dispColor();
obj.dispAutomobile();
end
end
end

测试代码:

rc = RedCar();
rc.dispThis(); bb = BlueBus();
bb.dispThis();​

参考资料:

https://blog.csdn.net/cwy0502/article/details/90924330

https://blog.csdn.net/u012814856/article/details/81355935

https://blog.csdn.net/weixin_34006468/article/details/87266145

https://blog.csdn.net/zhongbeida_xue/article/details/88601352

https://blog.csdn.net/u013985879/article/details/82155892

最新文章

  1. WPF仿百度Echarts人口迁移图
  2. if else 的令人防不胜防的奇葩错误
  3. BZOJ3246 [Ioi2013]Dreaming
  4. [http] http缓存机制
  5. ubuntu安装kernel3.10.34
  6. JAVA编程心得-多态设计初步
  7. SSIS 阻塞,半阻塞和全阻塞 (Non-blocking, semi-blocking and Fully-blocking) transformations清单
  8. Godiva_百度百科
  9. 使用c3p0与DBCP连接池,造成的MySql 8小时问题解决方案
  10. Oracle 10053
  11. centos7下安装docker(12.5容器在单个host上的网络总结)
  12. hdfs 操作 入门api
  13. 产品设计教程:如何理解 px,dp,dpi, pt,看这一篇就够了
  14. ping一个网段的cmd程序
  15. dedecms(织梦系统)如何更新手机版首页模板文件
  16. Entity Framework Code First 在Object Join Linq查询时出现全表查询的语句。
  17. proxy,https,git,tortoise git,ssh-agent,ssh-add,ssh,ssl,rsync
  18. 在一般处理程序里面读写session
  19. 使用 Angular 和 RxJS 实现的无限滚动加载
  20. Android 你可能忽略的提高敲代码效率的方式

热门文章

  1. 8-剑指offer: 替换空格
  2. 201871010108-高文利《面向对象程序设计(java)》第十一周学习总结
  3. echo和printf打印输出
  4. sed-grep命令
  5. Git命令行操作(三)
  6. MySql5.7InnoDB全文索引(针对中文搜索)
  7. [POJ1952]BUY LOW, BUY LOWER
  8. linux-部署1
  9. 「总结」插头$dp$
  10. VeeValidate——vue2.0表单验证插件