Question: I would like to ask question regarding internal helper class in C++. What is the best way to structure this? 

Let me clarify what do I mean by internal helper class by example.

```
// MyClass.h
class MyClass
{
    int myData;
    bool isSomething;
    ...
public:
    void DoSomething();
};

// MyClass.cpp
// This is what I mean by internal helper function. Helper function that's only visible int the implementation file (.cpp) but requires access to the private members of the class.
static void DoSomethingInternal( MyClass *myClass )
{
   // Access myClass private members
}

void MyClass::DoSomething()
{
    ...
    DoSomethingInternal(this);
    ...
}

```

I know that declaring friend function can be a solution. However, it makes the class declaration ugly. In addition, for every new helper function, I have to add a friend function.

Is there an idiom/design pattern for this? I have been searching in the Internet, but didn't find any.

Thank you in advance. Your answers are greatly appreciated.

Answer: 
There are couple of ways to accomplish that.

1. Use a helper class/function in the .cpp file if the helper functions don't need access to the data directly. I would recommend this method ahead of the next method.

In the .cpp file:

```
// Create a namespace that is unique to the file
namespace MyClassNS
{
   namespace HelperAPI
   {
      void DoSomethingInternal(MyClass* obj) { ... }
   }
}

using namespace MyClassNS;
void MyClass::DoSomething()
{
    ...
    // 
    HelperAPI::DoSomethingInternal(this);
    ...
}

```
2. Use the [pimple idiom](https://en.wikipedia.org/wiki/Opaque_pointer). When using this idiom, you can add any number of helper functions in the private data class without touching the public interface of the class.
The design pattern is simple: [don't use helper classes](http://blogs.msdn.com/b/nickmalik/archive/2005/09/06/461404.aspx). If a class should do something, let it do it itself.