Saturday, June 27, 2015

ExtJS Classes - OOPS

This article will explain you the  Ext JS’ concept of OOP and class-based programming.
  1. Classes and Instances
  2. Inheritance (polymorphism)
  3. Encapsulation 
  • ExtJS Object oriented programming


     Below Example to Understand EXTJS classes

     

     Parent Class calc

     Ext.define('calc', { //Define Key word to create Class in ExtJS
         x:0,
         y:0,
         constructor: function (config) {
             Ext.apply(this, config);
         },
         getSum: function () {
             return this.x + this.y;
         },
         getMultiplication: function () {
             return this.x * this.y;
         },
         getDivision: function() {
            return this.x / this.y;
         }
     });

    Child Class Add extends Parent calc

      Ext.define('Add', {
         extend: 'calc',
         add: function() {
             return this.getSum();
         }
     });


    Instance Created for class Add

     var sum = Ext.create('Add', {x:10, y:15});
     Ext.Msg.alert('Addition', sum.add()); 



    Pictorial representation of Class and objects


No comments: