1 / 4

PIMPL Idiom

PIMPL Idiom. Encapsulating Implementation. Nested Classes. nested class is a class declared inside another class inner class scope is the enclosing class scope limitation is the primary purpose for this construct

stinec
Download Presentation

PIMPL Idiom

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PIMPL Idiom Encapsulating Implementation

  2. Nested Classes • nested class is a class declared inside another class • inner class • scope is the enclosing class • scope limitation is the primary purpose for this construct • if object or method is mentioned outside of enclosing class, need to resolve the scope • can be private or public • can be forward declared and then defined outside • if forward declared, the forward declaration should be inside the enclosing class definition (elaborated type specifier does not work) • has access to private/public members of enclosing class • enclosing class has no access to private/public members of inner class

  3. PIMPL • C++ does not provide ways to hide class implementation details/data: private part has to be declared • clients include header file with class definition: exposed to implementation • pointer to implementation (PIMPL) idiom: aka opaque pointer, d-pointer, cheshire cat idiom • in private (implementation) section of class provide reference (pointer) to actual implementation • when interface methods are invoked, invoke corresponding implementation methods using the pointer • actual implementation class is defined and implemented in separately

  4. PIMPL (cont) • terms: • handle – class with exposed interface • body – implementation class • specifics • body needs to be forward declared • body is dynamically allocated – need to implement big three • good practice to nest body inside handle • advantages • encapsulates implementation, allows body modification without need to modify handle • speeds up compilation, provides binary compatibility • could be used in Memento and Bridge design pattern

More Related