As part of a .NET Core class library, I'm designing a typed client to communicate with a REST API. Let's assume this client deals with objects of type MyObject, and that this type has an internal constructor. To get to the point, I'm wondering whether it'd be appropriate to use ref parameters on update and delete methods so that remote changes are applied to the operands immediately, rather than requiring API users to manually keep track of state. This is especially concerning to me in the case of a delete, where I wouldn't want users to be able to erroneously use an instance of MyObject once it's been deleted remotely. Granted, I could introduce error handling to deal with that, but I wasn't sure whether ref would be a cleaner solution.
So which would be preferable? This:
public class MyClient
{
public MyObject UpdateObject(MyObject myObject, ParameterObject parameters)
{
return RemoteUpdate(myObject, parameters);
}
}
Or this:
public class MyClient
{
public void UpdateObject(ref MyObject myObject, ParameterObject parameters)
{
myObject = RemoteUpdate(myObject, parameters);
}
}
And likewise for delete. This:
public class MyClient
{
public void DeleteObject(MyObject myObject)
{
RemoteDelete(myObject);
}
}
Or this:
public class MyClient
{
public void DeleteObject(ref MyObject myObject)
{
RemoteDelete(myObject, parameters);
myObject = null;
}
}