let’s say I have an object in an OO language called Man, and Man has a property name. if I have a function that says hello to this man, should I send Man.name as an argument or just send Man. for example, in python:
def sayHello(Man):
print 'hello! ' + Man.name
def sayHello2(name):
print 'hello! ' + name
which one is better? why?
If your function needs the name, and no other properties of Man, just send the name. The reason is to reduce coupling (sayHello does not need to know the properties of Man).
If your function needs two or more properties of Man, you should probably pass the object. The principal is called “Preserve Whole Object” from Martin Fowler’s book Refactoring: Improving the Design of Existing Code.