我是靠谱客的博主 落后短靴,这篇文章主要介绍Matlab单例模式,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
classdef SingletonClass < handle methods(Access = private) function obj = SingletonClass() disp('SingletonClass construtor called!'); end end methods(Static) function obj = getIns() persistent ins; if isempty(ins) || ~isvalid(ins) ins = SingletonClass(); end obj = ins; end end end

注:persistent变量不会随着.m文件运行结束而被清除,如果需要清除,可以有以下几种方法:

1、clear all

2、clear classes

3、clear SingletonClass

4、delete(SingletonClass.getIns())

最后

以上就是落后短靴最近收集整理的关于Matlab单例模式的全部内容,更多相关Matlab单例模式内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部