Learn from Saki

Knowledge is power

This content is for registered users only. Please login.
Hello! To access your account, please Log in. Not a member? Sign up
  • Videos
  • Blog
  • Examples
  • Services
  • Add-ons
  • About

Extension or Plugin?

April 28, 2008 by saki 2 Comments

Code in this post can be obsolete, however, principles and theory may still apply.

Preface

I believe that many of Ext users have already thought about adding some custom functionality that is not present in core Ext Library to a class. Something that is specific to their applications or not that specific so that others could also be interested in such feature. OK, we have the idea, we know what the new code should do, we even know how to write it, but what should we write? An Extension or a Plugin?

Extensions and Plugins

The fact we are talking about them together and the fact that we can be even indecisive which one to use infers that they must have something in common. True, they have. They both add some functionality to an existing library or modify a feature of the library. Neither extension nor plugin can exist standalone; they have to have a component, a class, they extend or plug into.

Extension

An extension (in Ext world) is a derived class in fact. Let’s imagine we have a basic class with some general methods to which we want to add some more specific methods. So, using the inheritance framework of an library or a language we create new class that contains methods of both basic class and new added methods. We choose an existing Ext class, we extend it using Ext.extend function and the result is new class with new name. For example:
1
MyExtension = Ext.extend(Ext.Panel, {/* object with new properties and methods */});
Later on, when we need an object:
1
var myExtension = new MyExtension({/* optional configuration object */});

Plugin

Plugin does not need any exiting Ext class to exist. Although plugins often extend Ext.util.Observable it is not a must; they can be written from scratch. Sure, writing a plugin without having a target we want to plug it in has no sense so we always write plugins for an existing Ext class: panel, form, grid, data view, etc. For example, we create plugin as:
1
MyPlugin = function() {/* code */};
And then we use it this way:
1
2
3
4
var myPanel = new Ext.Panel({
     plugins:[new MyPlugin({/* optional config object */})]
    ,// rest of myPanel configuration
});

Extension or Plugin?

It depends… You can often achieve same result with extension or with plugin. Sometimes it is only that programmer likes plugins more so he writes a plugin or he likes extensions more so he writes an extension. However, plugins are more suitable for adding smaller features and extensions are more suitable for adding more complex functionalities. Plugins can be easily removed from components, extensions are usually more tied to applications.

Summary

  • An extension is a new class with a new name, based on an existing base class and created at definition time. Extension must be instantiated as any other class to work.
  • Plugin plugs into an existing class, is easily removed, is defined during definition time and is initialized during base class initialization.

Further reading

  • Extending an Ext Class
  • Writing an Ext Plugin
  • Author
  • Recent Posts
Follow me:
saki
I'm a well seasoned developer, consultant and educator of web applications based mainly on Sencha libraries, PHP, MySQL and Node.js. Besides (Apple) computers, I love photography and mountain biking.
Follow me:
Latest posts by saki (see all)
  • Ext, Angular, React, and Vue - June 27, 2019
  • The Site Resurgence - February 11, 2018
  • Configuring ViewModel Hierarchy - June 19, 2015

Filed Under: Know-how Tagged With: extension, extjs, javascript, Know-how, plugin

Comments

  1. Soundararajan says

    October 18, 2010 at 11:32 am

    Hi Saki,

    Its gave me the basic idea of writing the Plugin or extend. Thanks

    Log in to Reply
  2. Doug McDonald says

    December 9, 2011 at 10:10 am

    Thanks for the pointers Saki, certainly helps clear things up when wanting to develop upon existing Ext functionality.

    As an additional question, if you feel some functionality is suitable for the general community and not application specific, which would you say is the most accessible to users who wish to incorperate this new functionality in their app. Do you think most users would prefer to USE an extension or a plugin?

    Log in to Reply

We will be happy to hear back from you Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • Addons (2)
  • Architecture (14)
  • Examples (2)
  • ExtJS (26)
  • Howtos (16)
  • Javascript (1)
  • Know-how (32)
  • Linux (1)
  • Mac OS X (2)
  • SASS/CSS (2)
  • Snippets (9)
  • Theory (14)
  • Touch (6)
  • Tutorials (5)
  • What is a … (9)

Tag cloud

abstract class accordion application button class cluster column component config css definition deprecated design education event example extension extjs factory function form grid html initComponent items javascript Know-how knowledge layout Linux listener mysql old panel pattern php plugin render snippet sql sqlite state table touch tree viewpoint

Membership

Become a Member
Affiliate Program

Support

FAQ
Contact

Legal

Terms and Conditions
Licensing
Privacy Policy

Copyright © 2021 · Dynamik-Gen on Genesis Framework · WordPress · Log in