When refactoring old code we usually have the situation where we have a public member variable that we want to hide.
class A
{
public:
int x;
}
Now we could use Encapsulate Field to make accessor functions. This gives us the following:
class A
{
public:
int x;
int X() const { return x; }
void X(u16 val) { x = val; }
}
But what we really need as next step is to make the member variable private and replace all code accessing it with the appropriate accessor functions. In large codebases with widespread use of some basic classes this would come really handy.