@Dheeraj
In my case, if used the friend keyword in each helper class, there
would be just too many of them.
@Ondra Holub
In principle you can write every class this way:
class PublicClass
{
public:
// Some public stuff would be here
private:
class Internal;
Internal* internal_;
};
class Internal may be defined in cpp (cc) file so user cannot do with
it anything. In some cases pointer to instance of Internal may be
replced with reference, but the princip remains same.
That's a good idea. But what if there are other public classes (my
client classes) that need to access the functionality of class
Internal? That's why I came up with a general base class holding the
functionality (the helper classes).
I could make a combination of the friend feature and Ondra Holub's
PublicClass:
class Hidden_functionality // Holub's PublicClass
{
private: // changed to private
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1;// {}; implemented in some cpp file
class Helper2;// {};
class Helper3;// {};
Hidden_functionality() {}
Hidden_functionality(const Hidden_functionality&) {}
~Hidden_functionality() {}
friend class Client1;
friend class Client2;
};
class Client1 /*: private Hidden_functionality */
{
/* make use of helper classes */
};
class Client2 /*: private Hidden_functionality */
{
/* make use of helper classes */
};
peter koch wrote:
ma*******@googlemail.com skrev:
Now other programmers who include the *.h file won't be able to use the
helper classes that are meant to be internally used by the client
classes.
They actually could, by creating a new class inheriting from
Hidden_functionality.
Not anymore :)
No one can access the helper classes but Client1 and Client2.
By the way, peter koch, the "helper" classes are actually the real
implementations of the client classes. It's a handle/body pattern.