
195MATLAB
®
-Specic Techniques
end
end
% Concrete singleton implementation
% Note: this is deliberately placed *outside* the class,
% so that it is not accessible to the user
function obj = getInstance()
persistent uniqueInstance
if isempty(uniqueInstance)
obj = Widgets();
uniqueInstance = obj;
else
obj = uniqueInstance;
end
end
Another consideration when designing classes is that while handle classes are slightly
slower to create (due to multiple super-class overheads), they are typically much faster to
use. The reason is that handle classes are passed to functions by reference, whereas value
classes are passes by value