I want to understand if the following coding practice is good or bad practice.
I pass a Value Object to a method as a parameter and the called method is returning the same parameter Value Object. I particulary think since it the same object be referenced we dont need to put it as return type.
Class A
{
initStudent()
{
Student studentObj = new Student();
//do some processing
studentObj = processStudent(studentObj);
}
processStudent(Student pObj)
{
//do something
return pObj;
}
}
I think it is a good practice to return the object if the method modifies it. So the signature of the method makes it clear that the object gets modified and you don’t have implicit side effects.
If the method is not intended to modify the object you should not return it.