Call another classes member function or saved it in this class?

Hi everyone. I have a class B that needs to take information stored on another class A and use it times and times again. The two way I thought of doing it was having class B to call class A's member, or I can just get the A's member and save it in B class as a new member. That way, I dont need to ask from A over and over again. But, doing this will occupy more space. So which way is better?

Thanks,
Last edited on
1. Classes (aka type definitions) do nothing, but objects might interact.

2.
You have (one or more?) objects of type A and (one or more?) objects of type B.
An object of type B uses a value of type C frequently.
The value is retrieved form type A object(s).

Does retrieval of value change the type A object?
Can the value stored in A type object change between retrievals?
Is the type C value "small and simple" but the retrieval operation computationally expensive?

One should have answers to the questions above when considering whether it is beneficial to cache data in temporary variable.

You need even more solid reasons, if you want to cache data in a member variable of all type B objects.
@keskiverto,
I have a class A that only has number of row, column and a set of integers in it. This information is required by 100 of B objects and 1 of C object. Retrieval of value doesn't change object A in anyway(or at least I hope so).
About complexity, row and column are just number and used only few times in my program. But the set from A is used 8 times max in each B object, so 8*100=800times in all of B objects. And operations with the set is just finding numbers inside the set.
But im still not sure as im quite new.
Topic archived. No new replies allowed.