Design Pattern: Singleton (Creational)
Updated 1 Sep 2016
Intent: Ensures a class only has one instance and provide a global point of access to it .
Motivation: It's important for some classes to have exactly one instance. For example, it can be desirable to have only a single instance of a GUI. With a MATLAB® GUIDE built GUI, the driver or main function provides a global point of access which is executed to,
1. initially instantiate the GUI; and
2. subsequently bring the existing GUI into focus *not* creating a new one.
Refer to the comments in 'Singleton.m' and 'SingletonImpl.m' for detail on the implementation. The script 'testSingletonImpl.m' demonstrates the use of 'SingletonImpl.m'. Further, a corresponding UML class diagram is illustrated in 'Singleton_UML_Diagram.pdf'.
Refer to pp.127-134 Gamma et al. for more information on the Singleton Design Pattern.
Written by Bobby Nedelkovski
The MathWorks Australia Pty Ltd
Copyright 2009, The MathWorks, Inc.
 Gamma, E., Helm, R., Johnson, R. and Vlissides, J. Design Patterns : Elements of Reusable Object-Oriented Software. Boston: Addison-Wesley, 1995.
Bobby Nedelkovski (2023). Design Pattern: Singleton (Creational) (https://www.mathworks.com/matlabcentral/fileexchange/24911-design-pattern-singleton-creational), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Inspired: Matlab logging facility
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.