R
Ralph
Hi,
I was reading effictive C++ and some other books again and they all tell
you about hiding implementation details (proxy/pimpl/inheritance) but
they never really explain when to use it.
I am starting on a new project which is part library so I think it would
be good to hide the implementation for the public classes in the library
but this seems a lot of overhead to me (both when developing and runtime
overhead).
For example, it needs to interface with C and I created a class
MemoryBuffer which basically just allocates memory and allows some
operations on the memory buffer. This class is in this library and is
used by several client applications. So, should I hide the implementation
for this class? I think I would but somehow this seems like lots of
unneeded overhead.
Another example, I have exception classes which stores a message and some
other information. Should I hide this information?
Anyway, my concern is that if I just hide all implementation details I
might overdo the whole implementation hiding idea and make the code less
clear and maintainable. Are there any rules on when to hide
implementation and when not ?
The only rule I could find is basically 'hide everything and when the
profiler says it is slow, unhide it'. Is this a good approach ?
I hope you understand what I am trying to say and have some good advice.
Thanks,
Ralph.
I was reading effictive C++ and some other books again and they all tell
you about hiding implementation details (proxy/pimpl/inheritance) but
they never really explain when to use it.
I am starting on a new project which is part library so I think it would
be good to hide the implementation for the public classes in the library
but this seems a lot of overhead to me (both when developing and runtime
overhead).
For example, it needs to interface with C and I created a class
MemoryBuffer which basically just allocates memory and allows some
operations on the memory buffer. This class is in this library and is
used by several client applications. So, should I hide the implementation
for this class? I think I would but somehow this seems like lots of
unneeded overhead.
Another example, I have exception classes which stores a message and some
other information. Should I hide this information?
Anyway, my concern is that if I just hide all implementation details I
might overdo the whole implementation hiding idea and make the code less
clear and maintainable. Are there any rules on when to hide
implementation and when not ?
The only rule I could find is basically 'hide everything and when the
profiler says it is slow, unhide it'. Is this a good approach ?
I hope you understand what I am trying to say and have some good advice.
Thanks,
Ralph.