Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

design an application can plug-in 2

Status
Not open for further replies.

beeleegie

Programmer
May 15, 2002
42
HK
Hi, I want to design an application that can install plug-in after user installed the main application. Just like Apache, user don't need to reinstall whole application again.
Anyone know how to design the system that I can fulfil this task for future extensible use? Thanx in advance.
 
You're going to need an interface that defines how plugins and the main app talk to each other. Look at how Microsoft implemented COM, for one example, although you're unlikely to need anything that complex. Isn't Apache open-source? In which case it should be easy to look at how they did it.

A problem is that you won't know up front what the interface should be. Why not try to build the main app to include a couple of pluggable elements? That way you can see how the interface evolves.

Mike
 
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
 
Hey Beelegie,

Are you talking a web application? If so, its pretty simple:

Create the webpages for the given area, create a dll for the code behind of those pages, and upload them to the web server. Its really that simple.

D'Arcy
 
HA HA

Forgot I wasn't in teh ASP.NET forum. SIlly me.

Well, in teh chance taht you ARE doing a web app in .NET, it really is that simple.

;)

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top