This is a really useful technique - it's used inside some major C projects (one example is OpenSSL).
What this article doesn't seem to mention (but I only skimmed) is that you can enforce hiding (no access to private methods and data) by splitting header files into public and private. In the public definition of the object, include a void* private field; in the private definition you can define a private structure that this will point to. Private methods then cast the void* to the correct structure and manipulate it as required.
If other code only imports the public header then they have no way of accessing the private structure.
I learnt this at my previous employer, maintaining code written by an employee who had left before I arrived and who had a reputation as being "too clever" by those that remained. Given the standard of the rest of the company (only his code was written as OOC), I regret never having met him...
...on the other hand, it can be difficult to read (grep for private to see an example of what I describe above) and difficult to debug. Apart from inheritance, I think the big advantage of C++ over C is that it makes reading and debugging this style easier.
|