decorator - what C++ idiom / pattern is this -


i still new c++11.

some time ago asked following question:
best method implement abstract factory pattern

in order research more, want know name of c++ idiom.

i call pimpl here, not sure if correct name.

the intention of whole thing hide raw or smart pointer when returning shape object factory. using "pattern" factory able return 1 , same type, , specific implementation encapsulated inside object.

it similar decorator too, except not decorating anything.

one might spot similarity adapter well, except outside interface same "inside" interface.

class pimplshape : public shape{     shape *sh; public:     pimplshape(shape *sh) : sh(sh){     }      virtual ~pimplshape() override{         delete sh;     }      virtual void process() override {         sh->process();     } }; 

my personal opinion have cooked in between multiple idioms.

the idea of pimpl hide inner class provides actual functionality can change want without affecting users (qt extensively). if @ code there 2 things forbid - inheritance , fact methods implemented in class definition (so methods of inner class visible users of class). in case proper pimpl be:

// pimplshape.h class shape;  class pimplshape {     shape *sh_; public:     pimplshape(shape *sh);     ~pimplshape();     void process(); };  // pimplshape.cpp #include "shape.h" // defines shape::process() pimplshape can use  pimplshape::pimplshape(shape *sh) : sh_(sh) {  }  pimplshape::~pimplshape() {     delete sh_; }  void pimplshape::process() {     sh_->process(); } 

as can see here, shape class hidden users of pimplshape.h file.

if @ example point of view of functionality, seems want achieve crtp not way it.


Comments