473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to hide helper classes in *.h files?

Suppose you have a couple of helper classes that are used by 2 client
classes only. How can I hide these helper classes from other
programmers? Do you think this solution is a good idea?:

class Hidden_functionality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_functionality() {}
Hidden_functionality(const Hidden_functionality&) {}
~Hidden_functionality() {}
};

class Client1: private Hidden_functionality
{
/* make use of helper classes */
};

class Client2: private Hidden_functionality
{
/* make use of helper classes */
};
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.

Is there a better solution to this?

Nov 29 '06 #1
6 3513

ma*******@googlemail.com skrev:
Suppose you have a couple of helper classes that are used by 2 client
classes only. How can I hide these helper classes from other
programmers? Do you think this solution is a good idea?:
First, I do not understand why you want to hide anything.
class Hidden_functionality
{
protected:
If I wanted it to be useful only for Class1 and Class2, I'd make Class1
and Class2 friends and let everything in Hidden_functionality be
private.
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_functionality() {}
Hidden_functionality(const Hidden_functionality&) {}
~Hidden_functionality() {}
};
What is strange to me is that Hidden_functionality is all classes.
There is no data here. If Hidden_functionality only has (static)
member-functions, I'd just use free functions, declaring them in the
..cpp file only.
>
class Client1: private Hidden_functionality
As Hidden_functionality is currently declared, there is absolutely no
reason to inherit Client1 or Client2 from Hidden_functionality. And
even if Hidden_functionality had data members, I still see no reason
for inheritance unless there is a using directive somewhere, and even
then it would normally be smarter to forward.
{
/* make use of helper classes */
};

class Client2: private Hidden_functionality
{
/* make use of helper classes */
};
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.
>
Is there a better solution to this?
Yes. But for now, I'm not sure what (and why!) you are trying to
accomplish.

Nov 29 '06 #2
You have to use the concept of friend class in C++.

Make every thing public in helper classes and then define those two
classes as friends of helper classes.

Dheeraj
ma*******@googlemail.com wrote:
Suppose you have a couple of helper classes that are used by 2 client
classes only. How can I hide these helper classes from other
programmers? Do you think this solution is a good idea?:

class Hidden_functionality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_functionality() {}
Hidden_functionality(const Hidden_functionality&) {}
~Hidden_functionality() {}
};

class Client1: private Hidden_functionality
{
/* make use of helper classes */
};

class Client2: private Hidden_functionality
{
/* make use of helper classes */
};
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.

Is there a better solution to this?
Nov 29 '06 #3
Sorry, I mean make every thing private in helper classes.

Dheeraj

Dheeraj wrote:
You have to use the concept of friend class in C++.

Make every thing public in helper classes and then define those two
classes as friends of helper classes.

Dheeraj
ma*******@googlemail.com wrote:
Suppose you have a couple of helper classes that are used by 2 client
classes only. How can I hide these helper classes from other
programmers? Do you think this solution is a good idea?:

class Hidden_functionality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_functionality() {}
Hidden_functionality(const Hidden_functionality&) {}
~Hidden_functionality() {}
};

class Client1: private Hidden_functionality
{
/* make use of helper classes */
};

class Client2: private Hidden_functionality
{
/* make use of helper classes */
};
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.

Is there a better solution to this?
Nov 29 '06 #4
ma*******@googlemail.com napsal:
Suppose you have a couple of helper classes that are used by 2 client
classes only. How can I hide these helper classes from other
programmers? Do you think this solution is a good idea?:

class Hidden_functionality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_functionality() {}
Hidden_functionality(const Hidden_functionality&) {}
~Hidden_functionality() {}
};

class Client1: private Hidden_functionality
{
/* make use of helper classes */
};

class Client2: private Hidden_functionality
{
/* make use of helper classes */
};
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.

Is there a better solution to this?
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.

Nov 29 '06 #5
@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.

Nov 29 '06 #6
ma*******@googlemail.com wrote:
@Dheeraj

In my case, if used the friend keyword in each helper class, there
would be just too many of them.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Nov 29 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: karolina | last post by:
Hi, I have a webserver which some user have their own accounts on. I want to provide the users with some public classes which they may use use when they are making there own php code placed in...
13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
2
by: Mark Buxbaum | last post by:
Hi, Is is possible to use a collection class instance as a helper object in a class? For example: MyClass.h: ---------- class MyClass {
2
by: Stephen Walch | last post by:
Does the .NET Framework have and helper classes that will help my code generate and/or validate XML Names or NCNames? From the spec: NCName::= (Letter | '_') (NCNameChar)* /* An XML Name,...
2
by: Rasika | last post by:
Memory usage wise is it a good idea to specify methods in utility/helper classes as instance methods rather than static methods? Rasika.
8
by: Joe Johnston | last post by:
I need a Browser Helper object written in VB.NET Please point me at a good example. Joe MCPx3 ~ Hoping this MSDN ng three day turnaround is true. Additional info: What is a BHO? In its...
6
by: Mike P | last post by:
I have heard about helper classes, but can somebody please explain to me what they are and what they are used? *** Sent via Developersdex http://www.developersdex.com ***
6
by: Ralph | last post by:
Hi, I was reading effictive C++ and some other books again and they all tell you about hiding implementation details (proxy/pimpl/inheritance) but they never really explain when to use it. I...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.