zoukankan      html  css  js  c++  java
  • pimpl idiom

    pimpl idiom

    flyfish 2014-9-30


    pimpl是Pointer to implementation的缩写
    为什么要使用pimpl
    1最小化编译依赖
    2接口与实现分离
    3可移植

    pimpl idiom也被称作Cheshire Cat , Compiler Firewall idiom.,d-pointer
    这个技术在设计模式中作为桥接模式(Bridge pattern.)来描写叙述
    看MSDN的演示样例

    Pimpl header
    // my_class.h
    class my_class {
       //  ... all public and protected stuff goes here ...
    private:
       class impl; unique_ptr<impl> pimpl; // opaque type here
    };

    Pimpl implementation
    // my_class.cpp
    class my_class::impl {  // defined privately here
      // ... all private data and functions: all of these
      //     can now change without recompiling callers ...
    };
    my_class::my_class(): pimpl( new impl )
    {
      // ... set impl values ... 
    }

    实现部分被隐藏在class my_class::impl{......} 中

    简单描写叙述就是将一个类切割为两个类,一个提供接口。一个负责实现。


    既能最小化编译依赖,又能接口与实现分离。



  • 相关阅读:
    oracle行转列
    JVM设置空间大小
    Spring AOP 业务权限管理
    清晨漫步
    pull解析xml(android)
    今昔何昔
    Spring: Document root element "beans", must match DOCTYPE root "null
    xfire
    心之所向
    Oracle数据库连接
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/7351361.html
Copyright © 2011-2022 走看看