Be the first to rate this file! 1 Download (last 30 days) File Size: 1.35 KB File ID: #23472
image thumbnail

The Object of My Callback

by Dimitri Shvorob

 

29 Mar 2009

(object references with Matlab timers)

| Watch this File

File Information
Description

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?

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Scrolling display
This submission has inspired the following:
Order book simulation

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
timer callback object singleton Dimitri Shvorob 30 Mar 2009 14:40:13
oop per isakson 27 Oct 2011 12:27:43

Contact us at files@mathworks.com