views:
207answers:
4This looks much more C than C++. In any object-oriented language, you would use inheritance and virtual functions to get this behaviour.
Using an internal pointer to an implementation class is perfectly fine (the pimpl idiom), but this pointer would not normally be accessible to callers. And I don't get the interface pointer at all.
I am afraid the names used do not have the usual meaning, so without examples of what is put in or how they are used, it's going to be difficult to guess.
There are 2 design patterns that you should check, that make heavy use of this kind of self-recursion (at class level*):
And I am afraid that you are looking at something that fails to emulate either of those.
In the Decorator, the point is to add functionality. To this end you have an Interface of which derives a Concrete class and a Wrapper interface. Then various wrappers will derive of Wrapper and you can chain them:
Interface* interface = new Wrapper2( new Wrapper1 ( new Concrete() ) );
Each wrapper add some functionality, whereas here we only have perfect forwarding... so it's not a Decorator.
The Composite pattern is different. Its goal is to hide whether you treat with a collection of elements or a single element. The usual example is a tree: you can apply operations either to an entire subtree or just a leaf node if it's implemented with a Composite Pattern.
Once more, there is not such thing here.
So my best guess is that you have either a wild design (perhaps a misguided attempt to emulate a well-known pattern) or you haven't given enough information (source code) for us to figure out the role. It seems strange anyway.
*Note: by self-recursion at class level I mean that an object of class A points to another object of class A, but this does not mean (certainly) that it points to the same instance... otherwise we would have a Stack Overflow (pun intended). This not the same instance bit is certainly worth checking during the SetImplementation call: note that any cyclic reference would cause death by recursion.
I'm not sure if this is a classic example of the pimpl idiom, but if so, the point is to separate the interface (which should be stable) from the implementation details (which you should be relatively free to change).