Skip to main content
added 12 characters in body; deleted 1 characters in body
Source Link
Allbite
  • 2.5k
  • 1
  • 25
  • 23

In normalnon-Pimpl class headers the .hpp files the headerfile defines the public and private components of your class all in one big bucket.

Privates are closely coupled to your implementation, so this means your .hpp file really can give away a lot about your internal implementation.

Consider something like the threading library you choose to use privately inside the class. Without using Pimpl, the threading classes and types might be encountered as private members or parameters on private methods. Ok, a thread library might be a bad example but you get the idea: The private parts of your class definition should be hidden away from those who include your header.

That's where Pimpl comes in. Since the public class header no longer defines the "private parts" but instead has a Pointer to Implementation, your private world remains hidden from logic which "#include"s your public class header.

When you change your private methods (the implementation), you are changing the stuff hidden beneath the Pimpl and therefore clients of your class don't need to recompile because from their perspective nothing has changed: They no longer see the private implementation members.

http://www.gotw.ca/gotw/028.htm

In normal .hpp files the header defines the public and private components of your class all in one big bucket.

Privates are closely coupled to your implementation, so this means your .hpp file really can give away a lot about your internal implementation.

Consider something like the threading library you choose to use privately inside the class. Without using Pimpl, the threading classes and types might be encountered as private members or parameters on private methods. Ok, a thread library might be a bad example but you get the idea: The private parts of your class definition should be hidden away from those who include your header.

That's where Pimpl comes in. Since the public class header no longer defines the "private parts" but instead has a Pointer to Implementation, your private world remains hidden from logic which "#include"s your public class header.

When you change your private methods (the implementation), you are changing the stuff hidden beneath the Pimpl and therefore clients of your class don't need to recompile because from their perspective nothing has changed: They no longer see the private implementation members.

http://www.gotw.ca/gotw/028.htm

In non-Pimpl class headers the .hpp file defines the public and private components of your class all in one big bucket.

Privates are closely coupled to your implementation, so this means your .hpp file really can give away a lot about your internal implementation.

Consider something like the threading library you choose to use privately inside the class. Without using Pimpl, the threading classes and types might be encountered as private members or parameters on private methods. Ok, a thread library might be a bad example but you get the idea: The private parts of your class definition should be hidden away from those who include your header.

That's where Pimpl comes in. Since the public class header no longer defines the "private parts" but instead has a Pointer to Implementation, your private world remains hidden from logic which "#include"s your public class header.

When you change your private methods (the implementation), you are changing the stuff hidden beneath the Pimpl and therefore clients of your class don't need to recompile because from their perspective nothing has changed: They no longer see the private implementation members.

http://www.gotw.ca/gotw/028.htm

Source Link
Allbite
  • 2.5k
  • 1
  • 25
  • 23

In normal .hpp files the header defines the public and private components of your class all in one big bucket.

Privates are closely coupled to your implementation, so this means your .hpp file really can give away a lot about your internal implementation.

Consider something like the threading library you choose to use privately inside the class. Without using Pimpl, the threading classes and types might be encountered as private members or parameters on private methods. Ok, a thread library might be a bad example but you get the idea: The private parts of your class definition should be hidden away from those who include your header.

That's where Pimpl comes in. Since the public class header no longer defines the "private parts" but instead has a Pointer to Implementation, your private world remains hidden from logic which "#include"s your public class header.

When you change your private methods (the implementation), you are changing the stuff hidden beneath the Pimpl and therefore clients of your class don't need to recompile because from their perspective nothing has changed: They no longer see the private implementation members.

http://www.gotw.ca/gotw/028.htm