I recently got into discussion about how the method signature should look like for an API method which doesn't expose internal objects used by application to caller. Here is how situation looks:
Our API should expose one method say,
public int updateSummary(String summaryMessage) { update_in_DB(summaryMessage); if (success) return 1; return -1; }
or,
public void updateSummary(String summaryMessage) {
update_in_DB(summaryMessage);
}
This method can be called by clients to update summary of operations.
The debate was, what should be Return_Type?
i. void or,
ii. something like int or, enum which conveys information around whether that operation was successful or not.
iii. Return_Type can't be of type object/entity which represents actual object because it will expose internals of application to caller.
my point is, adding a return type like int/enum will make method testable (via unit testing) also, it enables caller to take action if this operation fails. But counter part to this was given that, it should be void and if operation fails error should get propagated to user because application should throw error indicating that something is wrong in deployment. Is anyone aware of any best practices or standards around this?