It may be a subjective question but I want to know what people feel is the best pattern for behavior of an object's save or delete methods?
When you setup a class that will contain Db record information I usualy end up declaring the objects Delete() and Save() methods as void. As these methods usualy take direct action on other properties of the object do we need to return anything else to confirm the action? On fails I just let the error handleing framework or implementig code handle any exception fall out.
I have seen alot of objects that send back a rows affected int or other return, what is the 'expert' opinion on this?
i.e. this:
public void Delete()
{
if (this.objectID == null || this.objectID == -1) { throw new exNotDbObject() }
//Do dB operations
this.objectID = null;
this.TimeRetrievedFromDb = null;
}
vs this:
public int Delete()
{
if (this.objectID == null || this.objectID == -1) { throw new exNotDbObject() }
int retVal = dataLayer.DeleteObj(this.objectID);
return retVal;
}