The Object of My Callback

版本 1.0.0.0 (1.3 KB) 作者: Dimitri Shvorob
(object references with Matlab timers)
1.9K 次下载
更新时间 2016/4/4

查看许可证

How can I have a timer whose callback points to an object? (For example, invokes a method on a particular instance of a user-defined class - possibly, the instance that 'hosts' the timer, when the timer serves as the object's 'heartbeat').
The solution I came up with employs Singleton pattern to create and access multiple instances, identifies those by id's, and hard-codes the id's into timer callbacks. (As a shortcut, sample class Widget identifies id with an 'existing' property, Color - now, no two widgets of the same color can be created - but this is not necessary, and 'getInstance' is easy to modify). Things get more complicated when one handles deletion of singletons, which included code does not do.

Is there a simpler way?

引用格式

Dimitri Shvorob (2024). The Object of My Callback (https://www.mathworks.com/matlabcentral/fileexchange/23472-the-object-of-my-callback), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2008b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Whos 的更多信息
致谢

参考作品: Scrolling display

启发作品: Order book simulation

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0

BSD