473,834 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_function ality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_function ality() {}
Hidden_function ality(const Hidden_function ality&) {}
~Hidden_functio nality() {}
};

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

class Client2: private Hidden_function ality
{
/* 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 3538

ma*******@googl email.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_function ality
{
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_function ality be
private.
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_function ality() {}
Hidden_function ality(const Hidden_function ality&) {}
~Hidden_functio nality() {}
};
What is strange to me is that Hidden_function ality is all classes.
There is no data here. If Hidden_function ality only has (static)
member-functions, I'd just use free functions, declaring them in the
..cpp file only.
>
class Client1: private Hidden_function ality
As Hidden_function ality is currently declared, there is absolutely no
reason to inherit Client1 or Client2 from Hidden_function ality. And
even if Hidden_function ality 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_function ality
{
/* 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_function ality.
>
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*******@googl email.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_function ality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_function ality() {}
Hidden_function ality(const Hidden_function ality&) {}
~Hidden_functio nality() {}
};

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

class Client2: private Hidden_function ality
{
/* 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*******@googl email.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_function ality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_function ality() {}
Hidden_function ality(const Hidden_function ality&) {}
~Hidden_functio nality() {}
};

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

class Client2: private Hidden_function ality
{
/* 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*******@googl email.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_function ality
{
protected:
// These helper classes provide some functionality that is
// only used by the client classes
class Helper1 {};
class Helper2 {};
class Helper3 {};
Hidden_function ality() {}
Hidden_function ality(const Hidden_function ality&) {}
~Hidden_functio nality() {}
};

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

class Client2: private Hidden_function ality
{
/* 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_function ality // 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_function ality() {}
Hidden_function ality(const Hidden_function ality&) {}
~Hidden_functio nality() {}

friend class Client1;
friend class Client2;
};

class Client1 /*: private Hidden_function ality */
{
/* make use of helper classes */

};

class Client2 /*: private Hidden_function ality */
{
/* make use of helper classes */

};

peter koch wrote:
ma*******@googl email.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_function ality.
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*******@googl email.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.c om/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
6197
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 their own directories. I want the code to be accessable via an interface (like h-files in c) but I do not want my code to be viewable to the users which are using my classes. Very much like a library or something.
13
74151
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 Form1.Visible = False Load (Form1)
2
1709
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
1765
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, minus the ":" */ NCNameChar::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender I want to strip out any offending characters and make sure my code only generates valid names.
2
3245
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
5737
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 simplest form, a BHO is a COM in-
6
49758
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
3969
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 am starting on a new project which is part library so I think it would be good to hide the implementation for the public classes in the library but this seems a lot of overhead to me (both when developing and runtime overhead).
0
10794
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9796
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9643
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10503
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10544
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.