Delegates vs target/action

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

Post Reply
Mazyod
Posts: 25
Joined: 04 Sep 2012, 16:05

Delegates vs target/action

Post by Mazyod »

Hello people of earth!

While exploring the C++ API, I couldn't help but notice the target action paradigm that was adopted by the API to implement callbacks. As far as I can tell, this gives a lot of flexibility and loose coupling for components, but in return, it's fragile and requires a precise management to get things through.

OK, so what?
Well, I was wondering if the delegation pattern would be a better fit for the API, especially with the recent adoption of the smart pointers. Arguably, the biggest headache in the delegation pattern is the properly holding a reference to the callback object and properly releasing the memory when it's over. Well, this burden can be carried by the smart pointers now! Needless to day, other great benefits of this pattern is the well defined interface it will introduce between the API and the code base.

The reason I took the effort to write this is because I really love smartfox more than any other alternative, and I am here to watch it evolve. It's also because I was having trouble sending a class method as a callback function, actually. Then I realized I had to send a pure function's pointer, and use that to call the context's method or something, which just made me remember the time I dealt with hooking C++ with ObjC, but those are two different languages, of course.

Anyways, I just wanted to throw this here and maybe it sticks, maybe not. The least I am hoping for is to start a healthy community discussion to learn a few things about designing APIs.

Best,
Post Reply