Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the basic idea behind Plugins? [closed]

Tags:

plugins

Wether you call it Addons, Plugins or extra peices of code that is connected with the original software later, it really doesn't matter. I would love to understand how they work, there has to be a simple explanation of how to design a Plugin System. Unfortunately, I never understood it, and there remains a lot of open question in my mind. For example, how does the program find a plugin? how does it interface with it? when is it preferable for a software to have Plugin System?


Thanks for all helpful answers. It seems I asked too open question, fortunately I got keywords to look for. I liked David answer though I am not a Java guy, but his talk made sense to me :)

like image 424
Khaled Alshaya Avatar asked Sep 21 '09 04:09

Khaled Alshaya


2 Answers

Plug-ins work by conforming to well-known interfaces that the main application expects to work with.

There are several ways in which a plug-in architecture actually works, but in general, these are the steps:

  1. Plug-ins are designed to match an interface that the application expects. For example, a simple application might require that plug-ins implement a IPlugin interface.
  2. Plug-ins are loaded by the application, usually when the app is starting up
  3. Plug-ins are often provided access to much of the data that the application manages. For example, Firefox plug-ins can access the current web page, and Eclipse plug-ins can access the open files.

Here are two ways (out of several) in which an application can find plug-ins:

  1. The plug-ins are known to exist in a particular folder, and the application knows to load plug-ins from that folder
  2. Each plug-in runs as a service, and the services are designed to work together (this is how an OSGi-based application works)

When plug-ins are found, they are loaded by the application (sometimes the job of a Class Loader).

A software architect might design a plug-in architecture when they expect that either the software provider or the user community will implement new features that were not originally part of the system. Two great examples are Eclipse and Firefox; other applications include Adobe Photoshop (for artistic techniques and graphical tools) and Winamp (for visualizations).

like image 139
David Koelle Avatar answered Sep 30 '22 13:09

David Koelle


  1. Create an interface that all plugins of a particular type will implement
  2. Write the code that will 'consume' the plugin against the interface only.
  3. Have a dynamic way to load a DLL containing the plugin type that implements your interface (for instance, have a configurable folder location to test whether any DLLs in that folder contain any types that implement your interface, and dynamically load any that do. In .NET this might use Assembly.LoadFile())

If you want to have a look at some source code, Paint.NET is free and open source, and has a plugin architecture.

like image 43
Mitch Wheat Avatar answered Sep 30 '22 13:09

Mitch Wheat