Matlab单例模式
程序员文章站
2024-02-01 18:17:58
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