classdef Calculator < handle & matlab.mixin.Copyable properties (Access = private) CalculatorDefaults = struct('ChemicalPotential', 1, ... 'EnergyComponents', 1, ... 'NormalizedResiduals', 1, ... 'TotalEnergy', 1); end properties (Access = public) ChemicalPotential; EnergyComponents; NormalizedResiduals; TotalEnergy; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %- Methods methods function this = Calculator(varargin) this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential; this.EnergyComponents = this.CalculatorDefaults.EnergyComponents; this.NormalizedResiduals = this.CalculatorDefaults.NormalizedResiduals; this.TotalEnergy = this.CalculatorDefaults.TotalEnergy; end function restoreDefaults(this) this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential; this.EnergyComponents = this.CalculatorDefaults.EnergyComponents; this.NormalizedResiduals = this.CalculatorDefaults.NormalizedResiduals; this.TotalEnergy = this.CalculatorDefaults.TotalEnergy; end end % % methods % end % - setters and getters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %- Methods methods(Access = protected) function cp = copyElement(this) % Shallow copy object cp = copyElement@matlab.mixin.Copyable(this); % Forces the setter to redefine the function handles to the new copied object pl = properties(this); for k = 1:length(pl) sc = superclasses(this.(pl{k})); if any(contains(sc,{'matlab.mixin.Copyable'})) cp.(pl{k}) = this.(pl{k}).copy(); end end end end methods (Static) % Creates an Instance of Class, ensures singleton behaviour (that there % can only be one Instance of this class function singleObj = getInstance(varargin) % Creates an Instance of Class, ensures singleton behaviour persistent localObj; if isempty(localObj) || ~isvalid(localObj) localObj = Simulator.Calculator(varargin{:}); end singleObj = localObj; end end end