Wednesday, July 15, 2009

Simple APIs responsibilities on arguments

public Student createStudent(Student student, Couse course)

 

Lets say the responsibility of this API is to save the student and return the saved version back (the saved version will have the key).

 

Some implications of this API is that

  1. If there is a failure, student and course objects should be left un-touched. If there were changes made before the createStudent() failed, all those changes should not be visible to the client of this API. This can be done by taking a copy of the student and course and letting createStudent() operate on that copy. That way if there is a failure, then the original student and course object remain intact.
  2. If the operation succeeds, the client of this APIs would usually require that all changes made by createStudent() be reflected in student and course. To achieve this, after all createStudent operations complete successfully, overwrite the copy that was made at that start of the call back into student and course.

No comments: