Lets say you create two objects: objectA and objecB. If objectA needs to send a message to objectB should it happen like this:
objectA.theMessage(objectB)
or like this:
objectB.theMessage(objectA)
A more concrete example:
Publisher p;
Subscriber s;
// way 1
p.addSubscriber(s);
// way 2
s.subscribeTo(p);
As you can see, the semantics of both messeges (functions) are the same, its just a matter of where the function should live in.
Is there a hard and fast rule that states which should be done? Or Is there a general guideline that helps you in determining which is the better design? Or Is this a case by case thing and no general guideline exists? If so, could you explain when I would use each. Can you think of any potential advantages/disadvantages of each?
Thank you very much for your time and knowledge!