Hello beeleegie.
I will use pseudocode in this post; I hope everyone could translate it into any OO language.
In the simplest way:
1. You must write a parent class:
abstract class CAbstractPlugIn
{
abstract int Exec();
}
(I don't like interfaces; in fact I don't like languages without multiple inheritance)
2. You must write a children class for every plug-in.
class CMyFirstPlugin child-of CAbstractPlugIn
{
int Exec()
{
int returnValue = CMyReturnValues.NOTHING_WAS_DONE;
// Do something...
returnValue = CMyReturnValues.SOMETHING_WAS_DONE;
// Do something...
returnValue = CMyReturnValues.ALL_WORK_DONE;
return returnValue ;
}
}
3. You must use a '.properties' file or something like that. This way, your app will know what plug-ins are installed. This file will be used to build menus, and it will be read by factories in order to know what class implements what pluggin, classpaths and such things.
4. Use factory pattern to invoke your pluggin:
// This method will be invoked by menuOnClick
// or something else
int ExecPlugIn()
{
...
CAbstractPlugIn myPlugin;
CFactory myFactory = new CFactory(myConfig)
...
myPlugin = myFactory.CreatePlugin(pluginCode);
pluginReturnValue = myPlugin.Exec();
...
}
So, a plugin setup program shall add 'CMyFirstPlugin' to classpath and modify the 'properties' file (or register, or a namedSharedMemory or whatever you are using). This way, next time the app starts (or next time the app checks configuration), menus will be rebuilt and your new plug-in will be enabled.
In a not so simple way:
You can use threading and solve this using a client/server architecture: the app will run in a thread and there will be a 'plug in server' running in another thread (may be in a different computer). So the app will 'ask' the plug-in server what plug-ins are ready to use and the app build its menus using this data. Then the app will use a 'RPC-like' protocol to get the plugin executed.
In a complex-but-powerful way:
You can use a web-services-like-architecture. Then there will be a lot of servers offering services (our plug-ins) and a lot of clients asking for this services.
Well I hope it will be useful for all of you.
Regards.
Nacho