2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

c++ > C++のためのAPIデザイン > pimplの利点と欠点

Last updated at Posted at 2015-05-15

引用: C++のためのAPIデザイン by マーティン・レディ (p82からp89あたり)

pimpl(Pointer to Implementation)の利点と欠点

利点

  • 結合度の削減 > 依存性を.cppに移動し、結合要素をすべて除去できる
  • コンパイル時間の高速化 > APIのインクルード階層が削減できる
  • バイナリ互換性の向上 > pimplオブジェクトはシングルポインタ1つのみ > オブジェクトのバイナリ表現を変更せずに、実装に大きな変更を加えることができる
  • レイジー割当て > mimplクラスは必要に応じて作成できる > ネットワーク接続などの制限のあるリソースやコストの高いリソースをクラスが割当てる場合に役立つ

欠点

  • 作成したオブジェクトごとに追加の実装オブジェクトを割当て > 割当て解除しなくてはいけない
  • コンパイラがconstメソッド内のメンバ変数の変更をキャッチしなくなる (メンバ変数がもはや別のオブジェクトに存在するから)
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?