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