Jump to content
  • Advertisement
Sign in to follow this  
ZealousEngine

Active Object question

This topic is 4145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have an Active Object, and instead of writing a overly complex 'proxy'/interface (the object itself is VERY complex), I figured I would 'trigger' most of the functionality via callbacks. Now, I know the callbacks will only be called by the 'servant', and only when its safe, so I want that callback to have access to the calling objects private members. I see two ways to do this... 1.) Make the active object a friend of the callback function (people always tell me NEVER to use friends though... are they really that evil?). 2.) Make the private data I want to access a 'central' static class, and inherit it into both the callback function and the active object. Or, is there a third, 'more correct' way to do it? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I'd recommend using functors to bind your callbacks to instances of your active object. If possible, just use the object itself as the functor so that you don't need an extra class.

In this case, friendship is perfectly acceptable; careful application of friend classes can actually help make an OO design cleaner. Overuse of friendship is often a symptom of bad design, but friend classes are often very useful and even required in some language's crippled type systems (mainly C++).

You might check into boost::bind as a means to avoid doing a lot of boilerplate functor code by hand, if you need this functionality in many places.

Share this post


Link to post
Share on other sites
Hrmm wait.. I AM using boost::bind to do the callbacks.. so youre saying when I call a function using boost bind, since im in essence calling it FROM my active object, it is considered a member function? So the callback function will have access to all the active objects private members?

BTW I kinda dont want to use friends, because that means my active object would have to declare ALL the potential callbacks as friends. Id rather my active object be unaware of any callbacks.

Share this post


Link to post
Share on other sites
I still havent found a good solution for this...

Does anyone have any other ideas for how you can give a callback function access to the callers members? I dont want to use friends, since I would have to declare ALL the callbacks inside the caller, which I dont want to do because the caller is supposed to be oblivious to all the different things it might be calling.

I would gladly pass a pointer to the private members I want to access, but that means I have to expose pointers to the 'attacher' (the guy attaching the callbacks to the active object). That could be dangerous.

*if only this worked...

boost::function<void()> func = boost::bind( &someFunction, _1, _2 );

The idea is, I need to wrap the function, and send it somewhere. I want the first two params of the function to be undefined, because only the caller knows what to assign to them (pointers to the private members).

*I think im missing something about boost::bind... What in the heck is the point of using placeholders (_1, _2) if you cant 'store' the function, and call it again at a later time?

[Edited by - ZealousEngine on May 14, 2007 7:23:50 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!