我正在研究 MATLAB 中的内容分发服务器的统计模型,并决定使用 OO 编程。这是我第一次使用 MATLAB 涉足 OO,但遇到了障碍。我正在尝试对与服务器的下载连接进行建模,目前它只是一个 MATLAB 计时器和一个布尔值。当计时器到期时,我想将isActive
字段设置true
为false
。我觉得很简单,但我已经为此奋斗了一天多。到目前为止,以下是该类的代码:
classdef dl<handle
properties
isActive = true
ttl = 0
end
methods
function this = startTimer(this, varargin)
this.ttl = timer('TimerFcn', @()killConnection(this), 'StartDelay',1);
start(this.ttl);
end
end
methods (Access = private)
function obj = killConnection(obj, varargin)
obj.isActive = false;
end
end
end