5.0

5.0 | 1 rating Rate this file 27 Downloads (last 30 days) File Size: 39.84 KB File ID: #24911
image thumbnail

Design Pattern: Singleton (Creational)

by Bobby Nedelkovski

 

02 Aug 2009 (Updated 05 Aug 2009)

A MATLABĀ® OOP implementation of the Singleton Creational Design Pattern

| Watch this File

File Information
Description

Intent: Ensures a class only has one instance and provide a global point of access to it [1].

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.[1] for more information on the Singleton Design Pattern.

Written by Bobby Nedelkovski
The MathWorks Australia Pty Ltd
Copyright 2009, The MathWorks, Inc.

Reference:
[1] Gamma, E., Helm, R., Johnson, R. and Vlissides, J. Design Patterns : Elements of Reusable Object-Oriented Software. Boston: Addison-Wesley, 1995.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
18 Nov 2011 Brad Stiritz

Thank you Bobby! for your excellent implementation of this classic design pattern. I especially appreciate your extensive documentation & excellent, highly-descriptive coding style.
5-stars well-deserved. If only all MATLAB code could look like this! Highly recommended.

Please login to add a comment or rating.
Updates
05 Aug 2009

Updated UML diagram to reflect inheritence from 'handle' class and usage of persistent variable 'uniqueInstance' in concrete class 'SingletonImpl'. Also MathWorks registered trademarks added to files.

Tag Activity for this File
Tag Applied By Date/Time
design pattern Bobby Nedelkovski 05 Aug 2009 13:33:38
singleton Bobby Nedelkovski 05 Aug 2009 13:33:38
creational Bobby Nedelkovski 05 Aug 2009 13:33:38
oop Bobby Nedelkovski 05 Aug 2009 13:33:38
object oriented programming Bobby Nedelkovski 08 Aug 2009 05:55:52
global Bobby Nedelkovski 14 Aug 2009 03:58:11
global variable Bobby Nedelkovski 14 Aug 2009 03:59:16
uml Bobby Nedelkovski 20 Aug 2009 01:12:42
design pattern Kyriakos 20 Jan 2011 06:05:05

Contact us at files@mathworks.com