00001 % Unique properties of singleton. This can be only accessed
00002 % with the getter/setter methods via any subclass of singleton.
00003
00004 classdef singleton < handle handler2
00005 %SINGLETON Abstract Class for singleton OOP Design Pattern
00006 % Intent: Ensures a class only has one instance and provide a
00007 % global point of access to it [1].
00008 % Motivation: It's important for some classes to have exactly one
00009 % instance. For example, it can be desirable to have only a
00010 % single instance of a GUI. With a MATLAB GUIDE built GUI, the driver
00011 % or main function provides a global point of access which is
00012 % executed to,
00013 % 1. initially instantiate the GUI; and
00014 % 2. subsequently bring the existing GUI into focus *not* creating
00015 % a new one.
00016 % Implementation: MATLAB OOP doesn't have the notion of static
00017 % properties. Properties become available once the constructor
00018 % of the class is invoked. In the case of the singleton Pattern, it
00019 % is then undesirable to use the constructor as a global point of
00020 % access since it creates a new instance before you can check if an
00021 % instance already exists. The solution is to use a persistent
00022 % variable within a unique static method instance() which calls the
00023 % constructor to create a unique 'singleton' instance. The persistent
00024 % variable can be interrogated prior to object creation and after
00025 % object creation to check if the singleton object exists. There are
00026 % two conditions that all subclasses must satisfy:
00027 % 1. Constructor must be hidden from the user (Access=private).
00028 % 2. The concrete implementation of instance() must use a persistent
00029 % variable to store the unique instance of the subclass.
00030 %
00031 % Refer to pp.127-134 Gamma et al.[1] for more information on the
00032 % singleton Design Pattern.
00033 %
00034 % Written by Bobby Nedelkovski
00035 % The MathWorks Australia Pty Ltd
00036 % Copyright 2009, The MathWorks, Inc.
00037 %
00038 % Reference:
00039 % [1] Gamma, E., Helm, R., Johnson, R. and Vlissides, J.
00040 % Design Patterns : Elements of Reusable Object-Oriented Software.
00041 % Boston: Addison-Wesley, 1995.
00042
00043 properties(Access=public)
00044 Data = [];
00045 end
00046
00047 methods(Abstract, Static)
00048 % This method serves as the global point of access in creating a
00049 % single instance *or* acquiring a reference to the singleton.
00050 % If the object doesn't exist, create it otherwise return the
00051 % existing one in persistent memory.
00052 % Input:
00053 % <none>
00054 % Output:
00055 % obj = reference to a persistent instance of the classix
00056 obj = instance();
00057 end
00058
00059 methods % Public Access
00060
00061 function v = get_Data(obj)
00062 v = obj.Data;
00063 end
00064
00065 function set_Data(obj, singletonData)
00066 obj.Data = singletonData;
00067 end % end1
00068
00069 function v = get.Data(obj)
00070 v = obj.Data;
00071 end
00072
00073 function set.Data(obj, singletonData)
00074 obj.Data = singletonData;
00075 end % end1
00076
00077 % And the if .. end issue.
00078 function v = showsTripleDot(obj, x_)
00079 function v_ = nested(x, y)
00080 v_ = nested(x, y);
00081 end
00082
00083 warning('showsTripleDot error %s\n', ...
00084 x_);
00085 if idx > length(obj.searched0)
00086 warning('model2:system volatility %f > calibrated %f\n', ...
00087 obj.volatility0, obj.searched0(end));
00088 idx = length(obj.searched0);
00089 end
00090
00091 for idx = 1:length(obj.searched0)
00092 switch idx
00093 case 1
00094 case 2
00095 otherwise
00096 end
00097 end
00098 end
00099
00100 function v = showsTripleDot1(obj, x_)
00101 v=v;
00102 end
00103
00104 % @fn void update(type obj, type returner)
00105
00106 end
00107
00108 end