欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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