The Object of My Callback

(object references with Matlab timers)
1,9K Downloads
Aktualisiert 4 Apr 2016

Lizenz anzeigen

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?

Zitieren als

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

Kompatibilität der MATLAB-Version
Erstellt mit R2008b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Whos finden Sie in Help Center und MATLAB Answers
Quellenangaben

Inspiriert von: Scrolling display

Inspiriert: Order book simulation

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.0.0

BSD