Thursday, September 18, 2014

Plugin

Plugins are features added out of box. It is not needed to know all the internals of an application to write a new plugin. And the application does not need to know about the feature internals. The new plugin feature is called the extension to the existing software. To make the total thing work, the extensions are registered to an extension point.

There are two things that incorporate plugin.

  • Loadable separate code.
  • Features/extensions that are registered at some extension point.

Example of a plugin

Suppose there is a need for feature to share a webpage content as emails. The feature is to send email with less interaction from the user. The user does not need to open a web application interface in the browser to send email. The feature can be implemented by a email plugin of the browser. The email plugin may insert a ‘send page’ button through registering in menu-item-extension point. And when the user clicks the ‘send page’ button from the browser-menu it opens up few text-boxes. Eventually the user types the address and subject and presses the send button to send the email.

Here is a component diagram to demonstrate the idea,

This is an email sending feature that is implemented by email plugin. And the plugin registers in menu-item-extension point. The plugin know very little about the core features or other plugins. And the core application does not know the internals of the plugin at all.

Actually this type of plugin exists for firefox browser. For firefox the plugins are called addons. And there is an addon named send page. The code is available here.

<menupopup id="menu_FilePopup">
  <menuitem id="menu_sendpagebyemail" label="Send page by email..." key="spbe_sendPageKey" 
    oncommand="spbe_showDialog();" insertbefore="menu_sendLink" accesskey="e"/>
</menupopup>

The xul code above registers a menu-entry labeled ‘Send page by email…’ in popup menu.

Finally the addon is provided in distributable package which firefox can load easily on demand.

The plugin system makes it possible to implement the beautiful correlation above.

Modules and plugins

Plugins and modules come hand in hand. Both modules and plugins are pieces of code. Both of them emphasize on separation of concern. In a module certain things are grouped together for development-ease or other purposes. But in a plugin they incorporate a feature and the basic idea is separation from the core features.

Sometimes module loaders facilitate a way to load plugins. In this case modules are also special type of plugins. They are loaded in the invisible extension point of the application binary.

Advantages

Developing parts as plugins is a useful approach. It comes with some benefits.

Make little things work quickly and easily

Plugins are written to give some specific features. And their concerns are limited. So is the development time. This time-tuning is important because of human bias of instant gratification.

Additionally the separated code can be tested and debugged in absence of other features(of which it is not dependent). Thus separation helps development,debugging and testing units. For example, if it is needed to think of a feature to write a browser plugin to send email, then it is not needed to worry about other browser plugins like video player or something. In this way it is possible to be more focused and productive.

Plugins improve motivation

Plugins makes it possible to write a small separate segment of a big task. So it gives the satisfaction of achievement. Though it is a portion of big task, still it motivates to finish the unit. It helps the unit-bias of human psychology to finish an unit task.

Plugins and extension point mechanism makes things simple

Extending a big application is big cognitive load. To know all the internals is mandatory. Otherwise it can lead to bugs. And there is need to know the big APIs too. But in plugin the scope is small. It is not necessary to worry about the whole application but only the plugin-api. For example, to write an email sending feature for existing browser which has plugin support, it needs very little for the integration,

  • To know the plugin API. (To know the skeleton plugin that does nothing.)
  • To know how to add an extension.

Additionally, there are other things like showing an edit box and sending an email, but they have nothing to do with the core application.

OK, this is all about plugins now. In future, there will be discussions on how people facilitate plugins in their applications.

1 comment:

Unknown said...

Thanks for comprehensive discussion.