Boost logo

Boost Users :

Subject: Re: [Boost-users] Pimpl framework comments/suggestions
From: Rob Riggs (rob_at_[hidden])
Date: 2011-04-17 19:23:21


On 04/17/2011 10:49 AM, Clinton Mead wrote:
> I don't really understand what you mean by this. What part of the
> implementation has leaked into the interface?
>
Hi Clinton,

What leaks is the implementation of the Pimpl itself. A Pimpl consists
of two distinct things: the interface (which the user cares about), and
the pointer (which the user need not know about). The user should not
know or care that a class is implemented as a Pimpl.

> Maybe I've missed the point but what I'm trying to achieve is the
> opposite. With all the implementations of pimpl I've seen, the
> "pointer" is leaked into the interface. I'm just trying to unleak it
> and separate it. The idea is that people can write interfaces without
> having to specify how pimpl is actually implemented.
>
It seems to me that this flexibility is for the benefit of the Pimpl
writer, and at the expense of the Pimpl user.

 From your example code:

|
unique_pimpl<interface, impl>::create();

|

This forces the implementation upon the user. || create() is not part of
the interface -- it's part of the Pimpl implementation leaking through.

Isn't this much simpler and more natural for the user:

unique_ptr<Klass> foo(new Klass);

Nothing here tells the user that Klass is implemented as a Pimpl. And
that is as it should be.

Regards,

Rob


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net