Is there a name for the idiom of using a friend class to hide what would have been private functions?


If a class has lots of private functions it seems undesirable to have them declared in the header file. It makes it harder for clients to parse the interface of the class and it increases compilation time.

One option is, of course, the pimpl idiom, but that adds a layer of indirection and also results in a memory allocation.

What follows is a example of hiding helper functions in a friend class that is defined in the implementation file.

Is there a name for this idiom?

Is there any reason not to do it?

class Foo
    void FuncA();
    void FuncB();
    int x;
    // more data...

    friend struct FooHelpers;
struct FooHelpers
    static void Helper1(Foo& f)
        // manipulate private data..
        f.x++; //etc.
    // Possibly more funcs...

void Foo::FuncA()

Source: Windows Questions C++