This article by Markus Ewald guides you through the design of a simple C++ plugin architecture based upon Factory classes. He also includes a fully working example implementation of his plugin system for you to download.
Markus presents a number of benefits of using plugins:
- Increased clarity and uniformity of code
- Improved modularization of code
- Shorter compile times
- Replacing/adding components
He also lists a further benefit of being able to use GPL code in a closed source project, although I do not believe that the GPL license allows this. The GPL FAQ states:
“If the program uses fork and exec to invoke plug-ins, then the plug-ins are separate programs, so the license for the main program makes no requirements for them. So you can use the GPL for a plug-in, and there are no special requirements. If the program dynamically links plug-ins, and they make function calls to each other and share data structures, we believe they form a single program, which must be treated as an extension of both the main program and the plug-ins. This means that combination of the GPL-covered plug-in with the non-free main program would violate the GPL.”