Matlab单例模式
程序员文章站
2022-05-18 23:03:29
classdef SingletonClass < handle methods(Access = private) function obj = SingletonClass() disp('SingletonClass construtor called!'); end end methods(... ......
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