1

Deciding whether an object should request data (by calling a function) or receive data (by having a function called from another object) is probably dependent on the exact situation. So how do I decide how to handle this?

If a specific example could help:

I'm currently designing an app using the Kinect camera. I want to split the signal and pass it to multiple objects that process the data (there is some bookkeeping involved, because I need to dispose a frame before requesting the next one). What should I do? Get data from the Kinect and store it, so other objects can request it? Or should I pass the data to the objects that need it?

A drawing with generic names, arrows indicate how data should flow:

Kinect ---> KinectManager |---> DataProcessor
                          |---> DataHandler
                          |---> DataSomething

My suspicion is the first case, because then I could have different objects request data, without KinectManager having to know about the objects. Though in the second case I could design an Interface with, for example, an Update() method that receives Kinect Data.

  • “Tell, Don't Ask” – gnat Mar 30 '15 at 7:34
  • @gnat I'm not quite sure that applies here. One object is responsible for getting data from the Kinect, the other is responsible for processing the data (and there could be multiple objects, each processing the data in their own way). Are you saying this should happen in the same object? – Simon Verbeke Mar 30 '15 at 7:41
  • 2
    most likely, what you call "data from Kinect" would better be an object that carries methods to work with that data, so that there is no need to expose data to other objects - that would be tell don't ask – gnat Mar 30 '15 at 8:10
  • @gnat Aha, I see, thanks! The situation is of course much more complicated than I can explain here, so there might be a better solution to my problem. But still, very usable advice. Thanks! – Simon Verbeke Mar 30 '15 at 9:25
1

Kinect manager can store Kinect data and emit an event or signal. Every other object listening to this event or signal can act upon it and retrieve these data.
This can be particularly useful if the other objects will not duplicate Kinect data to some other storage.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.