473,386 Members | 1,654 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.

Hiding implementation

Is there any alternative to hiding private members of a class without
using the Pimpl idiom? I know it probably doesn't affect performance
by much (although it would at least slightly), it just seems like such
an ugly hack and it detracts from the readability of the code.

Regards,
B.

Oct 29 '07 #1
5 1602
What you need to do is to go out and get laid and then think about the
question you're asking . Ask your self id this realy that important to
you . If it is then know this you're a faggot .

Oct 29 '07 #2
bo*******@gmail.com wrote:
Is there any alternative to hiding private members of a class without
using the Pimpl idiom? I know it probably doesn't affect performance
by much (although it would at least slightly), it just seems like such
an ugly hack and it detracts from the readability of the code.
The immediate one in my head is to use pure abstract base class, which
is basically a p-impl hidden behind virtual dispatch mechanism:

class dog_impl;

class dog
{
virtual void bark() const =0;
virtual ~dog(){}

static std::auto_ptr<dogcreate()
{
return std::auto_ptr<dog>(new dog_impl())
}
};
class dog_impl: public dog_impl
{
void bark() const;
~dog_impl();
};

But, on the user's stand point, this design is just not as intuitive to
use as p-impl, for the following reasons:

1) The interface class is a pure abstract class although it portraits a
concrete one and shall be used as a concrete one.

2) The user has to call a factory function to create an instance.

3) Assignment and copying are not easy to implement. In fact, since the
user is only given an effective pointer, any operator overloading will
be unavailable.

4) The concrete class is not readily derivable.

5) The problem complicates exponentially when more classes are derived
from the same base class.

>
Regards,
B.
Regards,
Ben
Oct 29 '07 #3
Hi

bo*******@gmail.com wrote:
Is there any alternative to hiding private members of a class without
using the Pimpl idiom? I know it probably doesn't affect performance
by much (although it would at least slightly), it just seems like such
an ugly hack and it detracts from the readability of the code.
Using inheritance and interfaces is often an option. Paired with a factory
of some kind, you wouldn't give away any internals besides the public
interface.

Markus

Oct 29 '07 #4
Thank you both for your input. The above methods seem to suffer from
the same problems of roundaboutness as pImpl, with other associated
problems. So I guess it really comes down to the language's design.
Why did C++ choose to not allow a program to define certain parts of a
class in seperate places (eg public interface in header file, and the
rest elsewhere).

Regards,
B.

Oct 29 '07 #5
On Oct 29, 11:42 am, boroph...@gmail.com wrote:
Thank you both for your input. The above methods seem to suffer from
the same problems of roundaboutness as pImpl, with other associated
problems. So I guess it really comes down to the language's design.
Why did C++ choose to not allow a program to define certain parts of a
class in seperate places (eg public interface in header file, and the
rest elsewhere).
Because there's no way to implement it otherwise, and still meet
the other constraints (integration with the C development
environment, etc.).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 29 '07 #6

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

Similar topics

11
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give...
5
by: Amir S. | last post by:
Hi, I'm a newbie to C++ (2 weeks into the course). We were given this assignment to write some code that reads a set of integers (grades) from a file (filename passed by console), outputs them...
0
by: Tom Z. | last post by:
Hi All, I'm trying to make an assembly in C# to use as a COM server. I'm building as normal and ruinning regasm at the end. Everything is generally working, except that I'm having a problem...
1
by: Tom Z. | last post by:
Hi All, I'm trying to make an assembly in C# to use as a COM server. I'm building as normal and ruinning regasm at the end. Everything is generally working, except that I'm having a problem...
4
by: Howie | last post by:
Hi, i have a normal class: //test.h class CForwardData; class CTest { CForwardData *pData;
8
by: Jeroen Smits | last post by:
To Microsoft or other people who are interested, I have a feature request: I would really like to have an option to 'hide' a property or method from an inherited class. For example when I create...
10
by: Bruce | last post by:
I posted this on the dotnet.languages.vc group but did not get a response. I figure that I could apply what I learn from CSharp to VC, so here goes. I have a class in a class assembly, that...
2
by: subramanian100in | last post by:
Is my following understanding correct ? Data abstraction means providing the interface - that is, the set of functions that can be called by the user of a class. Information hiding means...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
27
by: matt | last post by:
Hello group, I'm trying to become familiar with the information hiding design rules, and I have a lot (3) of questions for all you experts. AFAIK, a generic module has 2 files: ...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.