On 1/27/2010 7:16 AM, Jimmy Johnson wrote:
> I am not up to c-proficiency yet to understand what you mean.  Do you mean 
> put these features/pattern into the class and make them static?
>    

Yes. That may or may not work. Object functions have an implicit "this" 
pointer in their argument list, which you may need in the callback 
unless you can determine the object to use from the other parameters.

> What is "delegate to" a singleton?  I need to instantiate more than one 
> object of type displayable so making it a singleton will not work.  Can you 
> explain "delegate to a singleton"?
>    

A singleton is an object where there is only one object of its class 
ever instantiated. Typically you use language features such as a private 
constructor and non-virtual destructor to ensure the class cannot be 
extended, then create the instance and set a static const variable to 
it. You then provide a static function to get a reference to the singleton.

You can have static functions that delegate to object functions on the 
singleton, so users of your class do not need to know about the specific 
object. This works well for some designs, poorly for others. It really 
depends on whether the singleton is hard-coded or configurable.

Another alternative is if you want to restrict object construction and 
delegate from static functions, you can use a multiton pattern. You 
would store references to your objects in a hashtable or tree, i.e. an 
associative array. You would have some key provided by the callback 
which would retrieve the object on which to act, and then act on it.

Try searching wikipedia for "design pattern (computer science)" for more 
info. That's the basics. I am not sure if this will work for your 
situation, but it sounds like it is a new topic for you so it is worth 
learning about regardless.

-- 
John Gaughan
http://www.jtgprogramming.org/

Reply via email to