What type of method to use for the Delete or Save object?

This may be a subjective question, but I want to know what people feel, is this the best example of behavior of methods for saving or deleting objects?

When you set up a class that will contain information about the Db record, I usually declare the Delete () and Save () objects as void. Since these methods usually take a direct action on other properties of the object, do we need to return anything else to confirm the action? In the event of a failure, I simply let you handle the error processing the framework or implementation code, any exception.

I have seen many objects that send strings affected by int or other returns, what is an โ€œ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;
}
+3
1

int Delete(). , ( ) , - , , .

, void Delete() , ( ), , , , .

+1

Source: https://habr.com/ru/post/1728068/


All Articles