Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:49:32+00:00 2026-06-17T14:49:32+00:00

Possible Duplicate: Pimpl idiom vs Pure virtual class interface In hiding implementation, I’ve read

  • 0

Possible Duplicate:
Pimpl idiom vs Pure virtual class interface

In hiding implementation, I’ve read a lot about the “proxy class” or “handle class” or “cheshire cat smile” technique where you essentially include a pointer to your “real” class as a data member in your public/proxy class, and then implement everything in the “real” class.

But I was looking at some sample code and noticed another technique that seems to be easier, as it doesn’t require you to also write the “dummy” methods in the handle class to then call the real methods in the handle class, nor does it require any data members at all, and overall just seems more streamlined.

The technique is to simply define all your public methods as a struct (or a class where everything is public) and all virtual=0 member functions with nothing more. Thus there is no implementation. Then, define a static function that returns a pointer to this struct so the client can use the class. But behind the scenes this method actually returns a subclass of the struct, where you can then have much more going on inside this subclass.

If this is so straightforward and I would argue is more elegant than a public class including a data member that is a pointer to a separate class, and having to implement the public class’s calls to the data member’s methods, then why isn’t this the technique most discussed in hiding implementation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:49:33+00:00Added an answer on June 17, 2026 at 2:49 pm

    As noted on this article:

    The reason why most people recommend the PIMPL approach is that it has some distinct advantages:

    • Factory functions are not needed, you can use new(), delete() or
      create objects on the stack.
    • You can subclass easily.
    • The interface methods are not virtual, so calling them might be
      faster. (On the other hand, we need an extra memory fetch to get to
      the implementation object.)
    • PIMPL can be introduced in an existing class without changing its
      external interface or its relation to other classes.

    The abstract class method has some advantages of its own:

    • Cleaner code and a lot less typing, since we don’t have to write
      forwarding stubs for the methods in the public interface.
    • Multiple classes can implement the same interface. We can statically
      or dynamically select which particular implementation we want to use,
      which gives us more flexibility.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is Ruby’s double-colon (::) all about? pardon for my laziness. I
Possible Duplicate: How can a Java program use files inside the .jar for read
Possible Duplicate: Arithmetic operator overloading for a generic class in C# Here is the
Possible Duplicate: When should you use 'friend' in C++? I see a lot of
Possible Duplicate: Qt equivalent of PathAppend? Is there a class that handles file paths
Possible Duplicate: Objective C: what is a (id) sender? I have some questions about
Possible Duplicate: When should you use a class vs a struct in C++? When,
Possible Duplicate: Python passing list as argument I looked for many topics about that,
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.