Topic: Rimpl loosen dependency ?
Author: "Ali Cehreli" <See.signature@for.email.address>
Date: 5 Sep 2001 14:23:09 GMT Raw View
qazmlp <qazmlp1209@rediffmail.com> wrote in message
news:db9bbf31.0109021750.25f3eebb@posting.google.com...
> > > > > > Heard that Pimpl loosen the dependency between the
associated classes
> > > > > > . What about Rimpl and also having 'has a' relation ? Will
these ways
> > > > > > loosen the dependency ?
> > > > class simple
> > > > {
> > > > public:
> > > > file://public functions
> > > > private:
> > > > simpleimpl simpleimplobject; file://case 1
> > > > simpleimpl& simpleimplobject; file://case 2
> > > > simpleimpl* simpleimplobject; file://case 3
> > > > };
> > > > In case 3, compile time dependency is loosened. What about the
cases 1 & 2
> I finalize my decision that only pimpl will loosen the dependency ,
> Not others given above.
In case 1, the compiler needs to see the definition of simpleimpl at
least to calculate the size of 'simple'. Even the stack allocation
requires this. So simple.h depends on simpleimpl.h for case 1.
For case 3, the object contained in 'simple' is just a pointer and the
size of a pointer is well known by the compiler at compile time. Just a
forward declaration is sufficient:
class simpleimpl;
class simple{};
The forward declaration could be within 'simple' if simpleimpl was a
sub-class:
class simple
{
class simpleimpl;
};
Case 2 is the same as case 3: the compiler does not need to see the
definition of simpleimpl.
Both case 2 and 3 reduce compile time dependencies.
> I want to learn the basics.
Using pointers or references reduce compile time dependencies. This is
basic :)
> Please explain my doubts. When my friends claim that whatever they
> talk about C++ are correct, then I should be in a position to answer
> that.
>
> a) say I have testclass and testclassimpl. Should testclassimpl
> contain only the members OR can it contain methods.
I think it is better to have testimpl contain both the member variables
and the member functions and testclass have forwarding functions only.
> b) any low level disadvantage of these impl classes ?
It looks like the forwarding functions have some runtime cost but it is
easy for the compiler to optimize away in some cases. (Could I be more
unclear :)
--
Ali dot Cehreli at InviscidNetworks dot com
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Herb Sutter <hsutter@acm.org>
Date: 7 Sep 2001 15:36:00 GMT Raw View
qazmlp1209@rediffmail.com (qazmlp) writes:
> a) say I have testclass and testclassimpl. Should testclassimpl
> contain only the members OR can it contain methods.
>
> b) any low level disadvantage of these impl classes ?
Check out Exceptional C++'s section "Compiler Firewalls and the Pimpl Idiom"
(Items 26-30), particularly:
- Item 29 is devoted to your question (a). The Item 29 questions are:
"1. What should go into XImpl? There are four common disciplines.
- Put all private data (but not functions) into XImpl.
- Put all private members into XImpl.
- Put all private and protected members into XImpl.
- Make XImpl entirely the class that X would have been, and
write X as only the public interface made up entirely of
simple forwarding functions (a handle/body variant).
What are the advantages/drawbacks of each? How would you
choose among them?
2. Does XImpl require a pointer back to the X object?"
- Item 30 is devoted to your question (b), particularly performance. Its
three questions are:
"1. What is the Pimpl Idiom s space overhead?
2. What is the Pimpl Idiom s performance overhead?
3. Discuss Attempt #3. Can you think of a better way to get
around the overhead?"
I think the info you're looking for is all in there. Best wishes,
Herb
---
Herb Sutter (http://www.gotw.ca)
Secretary, ISO WG21 / ANSI J16 (C++) standards committee
Contributing Editor, C/C++ Users Journal (http://www.cuj.com)
* Check out THE C++ Seminar: http://www.gotw.ca/cpp_seminar
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: qazmlp1209@rediffmail.com (qazmlp)
Date: 3 Sep 2001 17:26:47 GMT Raw View
qazmlp1209@rediffmail.com (qazmlp) wrote in message news:<db9bbf31.0108310429.3d
1f4359@posting.google.com>...
> Attila Feher <Attila.Feher@lmf.ericsson.se> wrote in message news:<3B8F2BA6.7F
59442@lmf.ericsson.se>...
> > qazmlp wrote:
> > >
> > > Attila Feher <Attila.Feher@lmf.ericsson.se> wrote in message news:<3B8E5E6
4.B1FC8EAA@lmf.ericsson.se>...
> > > > qazmlp wrote:
> > > > >
> > > > > Heard that Pimpl loosen the dependency between the associated classes
> > > > > . What about Rimpl and also having 'has a' relation ? Will these ways
> > > > > loosen the dependency ?
> > > >
> > > > It is Pimpl (Pointer to IMPLementation).
> > > >
> > > > I probably don't get your question, but I will answer to what I
> > > > understood:
> > > >
> > > > You _can_ take Pimpl as a "has a" relationship. The "main" class is an
> > > > "interface", which "has an" implementation.
> > > >
> > > > Was this the question?
> > > >
> > > > Attila
> > >
> > > class simple
> > > {
> > > public:
> > > //public functions
> > > private:
> > > simpleimpl simpleimplobject; //case 1
> > > simpleimpl& simpleimplobject; //case 2
> > > simpleimpl* simpleimplobject; //case 3
> > > };
> > >
> > > Here 'simpleimpl' class is the implementation class for 'simple' class.
> > >
> > > In case 3, compile time dependency is loosened. What about the cases 1 & 2
> >
> > What about them? Did you read up on pimpl before starting to deal with
> > it? Is this a homework assigment or a test question? Do you _know_ how
> > pimpl loosens the dependency, what it the "trick"?
> >
>
I finalize my decision that only pimpl will loosen the dependency ,
Not others given above.
I want to learn the basics. That's why I am asking these doubts.
Please explain my doubts. When my friends claim that whatever they
talk about C++ are correct, then I should be in a position to answer
that.
Whatever I know about the impl classes, I have given it here.
impl classes loosen the dependency between the classes.
class A will 'have a' pointer to AImpl class. Because of this, the
direct dependency is reduced. whenever the class changes , it is not
needed to recompile. impl class will contain the members of the class
which is implemented.
I have some questions
---------------------
a) say I have testclass and testclassimpl. Should testclassimpl
contain only the members OR can it contain methods.
b) any low level disadvantage of these impl classes ?
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Albrecht Fritzsche <albrecht.fritzsche@alfabet.de>
Date: 4 Sep 2001 20:53:17 GMT Raw View
qazmlp wrote:
>
> I have some questions
> ---------------------
>
> a) say I have testclass and testclassimpl. Should testclassimpl
> contain only the members OR can it contain methods.
Sure it can contain methods either, the testclass shouldn't access
impls data directly.
> b) any low level disadvantage of these impl classes ?
The forwarding from the testclass to the impl class adds an
additional function call - but using inlined test class forwarding
functions should eliminate this disadvantage.
Ali
--
Albrecht Fritzsche, Software Developer
alfabet meta-modeling AG,
leibnizstr. 53, 10629 berlin, germany
http://www.alfabet.de
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]