Say you had two classes A and B. If the relationship between is has-a
i.e. A has-a B
how can you pass information from B into A? Say for example in B you work out a calculation and need the answer in A.
Is there any other way of doing this besides passing a pointer to class A into class B and calling a function which takes the answer as a parameter.
Hope this makes sense,
MD.
Sorry I should have been more specific
quote from my comment below.
“well I gave a simple example. I am programming this in java and my class B runs a new thread and and will calculate the answer. Therefore I cannot just call the function from class A as I don’t know when the calculation will be completed.”
The method in A that needs the result of the computation should call into the method in B that does the computation.
This answer is so obvious that there may be something you’re not telling us (?)Ok, so the question is really about threading. Yes, then passing a reference to owner object and calling back into it may be a good idea. A better idea might be to return a future object that encapsulates the result of the computation.