Tuesday, October 21, 2014

Plugin and object oriented programming

Object oriented programming has the features like class, object, abstraction, encapsulation, polymorphism, inheritance. Interestingly plugin has some of those features. This is a continuous effort to investigate plugins.


A plugin is simply a singleton object. It can be initiated and destroyed. And the registered extensions are it’s fields in analogy to an object.


Plugin can use any named extensions even they are not registered by any actions. In this way they are less specific and abstract. For example, an application lets plugin to do certain things before exit. And it executes the actions under the onQuit extension point. Initially it can be empty.

On some point of execution a new plugin may be loaded that registers action to onQuit. Suppose the action is just to print Good Bye on the screen. So before the application exists it executes the action registered at onQuit and eventually it says Good Bye to the user.


Encapsulation makes your code more flexible, because the developer is not concerned about who is using the inner code. And the inner code can be changed anytime without modifying the other plugins. It is like advertising less makes things flexible(less is beautiful). Plugin just hides its internal code blocks as they are not registered to any extension point.


Plugin has the basic feature of overriding. It lets a code block to register to an extension point. In this way it overrides the behavior of that extension point.

Suppose in the earlier example, we load a new plugin which overrides the onQuit with action to print See You. In that case the application may execute both the actions before exit resulting it to say Good Bye See You .


Polymorphism is the idea of abstraction. It is the idea that the behavior of the code may be changed. And Plugin has this idea too. Different plugins make the application behave in different way. In the earlier example of inheritance, the behavior is changed from doing nothing to saying Good Bye and to saying Good Bye See You before exit.

Advantages of plugins over object oriented design

  • Object oriented programming is sometimes a mess. Plugins are good point of decoupling. The figure below shows the idea.



No comments: