Consider the following example:
class Foo
{
private Bar x;
// ...
public Bar getAndResetX()
{
Bar result = x;
x = new Bar();
return result;
}
}
Is there an established naming conventions for such methods? Like yieldX, transferX or something?
We used to have the convention Adopt and Orphan as a prefix to provide intention in the method name (taken from Taligent book on C++).
You could use something similar to provide ownership clues to the objects. Quite frankly though I would stick with the Java convention of using add and remove. They provide enough intention and other programmers will not need to read a comment explaining the new convention.