question about designing two classes in c++ without lessening encapsulation
i have two class:
so this is what those class will do:
c = new Canvas;
void send_to_canvas(DATA &d)
void update_data(DATA &d)
data = d;
firstly, class Robot is directly exposed to the user/programmer
then, class Robot will send the data as reference to class Canvas
class Canvas will draw the data on gui window
the problem is, class Canvas also has capabilities to interact to user/programmer by capturing mouse click event (for example). generally gui libraries work like this. when this event happens, it should modify the data both in class Robot and Canvas.
Of course, I can do this easily by sending data as pointer (not as reference), right? but it means class canvas can modify data as it wishes and this will lessen encapsulation.
What is the best way?
shall I create a flag in class Canvas to tell class robot that mouse click event occurs, and class Robot will always check this flag so that data modification is done only by class Robot? this is an over killed solution.
or shall I make class Canvas a friend class? friend class is also lessening encapsulation.
I hope my question is clear.