SlideShare uma empresa Scribd logo
1 de 25
Rich Mobile Apps with Sencha Touch
Part II – Class System
Rich Mobile Apps with Sencha Touch
Part II – Class System

ExtJs And Sencha - 2 products that form the
Sencha SDK. They are considered the best UI
frameworks ever made for web applications.
As we saw in the previous presentation they
work cross platforms, cross browser but most
importantly they deliver high quality and user
experience that used to exist only in native
applications.

Best User Experience
Rich Mobile Apps with Sencha Touch
Part II – Class System

Better
Developer Experience
Rich Mobile Apps with Sencha Touch
Part II – Class System

The Sencha Class System was first introduced in Ext JS 4.0 and
was a major step forward in making it easy to build object oriented
JavaScript code. As a core part of the Sencha JavaScript platform, it’s
now a shared component between Ext JS and Sencha Touch 2.
Ext JS and Sencha Touch 2 use the class system internally to
manage dependencies, make code more reusable as well as provide a
rich set of features that are commonly found in other class-based
programming languages.
Rich Mobile Apps with Sencha Touch
Part II – Class System

Class
System
Event System
Data Package
Widgets & Layouts
…
Rich Mobile Apps with Sencha Touch
Part II – Class System

Why do we call it a class system?
Prototype-based

Class-based
Rich Mobile Apps with Sencha Touch
Part II – Class System

Flexibility

Sencha
Class
System

=

Programmer
Familiarity
Predictability
Rich Mobile Apps with Sencha Touch
Part II – Class System

Key Benefits
Learn

Develop

• Consistent
• Familiar

• DRY
• Debuggable
• Testable

• Automatic dependency resolution

Deploy
Rich Mobile Apps with Sencha Touch
Part II – Class System

Namespacing & Code Organization
1. OrganizationName.group[.subgroup].ClassName
2. One class per file
3. File name matches class name
• Ext.chart.Label
• Ext.data.writer.Xml
• MyApp.field.Password

 Ext/Chart/Label.js
 Ext/data/writer/Xml.js
 MyApp/field/Password.js
Rich Mobile Apps with Sencha Touch
Part II – Class System

Class Definition
Ext.define('My.sample.Person', {
constructor: function(name) {
this.name = name;
},
walk: function(steps) {
alert(this.name + ' is walking ' + steps + ' steps');
}
});
 Class definition is more than just inheritance
var tommy = new My.sample.Person('Tommy');
 Automatic namespace allocation
tommy.walk(5); // alerts 'Tommy is walking 5 steps'
 Classes are aware of their own names
 Asynchronous vs. synchronous
Rich Mobile Apps with Sencha Touch
Part II – Class System

Inheritance
Ext.define('My.sample.Person', {
constructor: function(name) {
this.name = name;
},
walk: function(steps) {
alert(this.name + ' is walking ' + steps + ' steps');
}
});

Ext.define('My.sample.Developer', {
extend: 'My.sample.Person',
code: function(language) {
alert(this.name + ' is coding in ' + language);
}
});
var tommy = new My.sample.Developer('Tommy');
tommy.walk(5);
// 'Tommy is walking 5 steps'
tommy.code('JavaScript');
// 'Tommy is coding in JavaScript'
Rich Mobile Apps with Sencha Touch
Part II – Class System

Inheritance
Ext.define('My.sample.Developer', {
extend: 'My.sample.Person',
code: function(language) {
alert(this.name + ' is coding in ' + language);
},
walk: function(steps) {
if (steps > 100) {
alert('Are you serious? That`s too far! I`m lazy');
} else {
return this.callParent(arguments);
}
}
});
var tommy = new My.sample.Developer('Tommy');
tommy.walk(50); // "Tommy is walking 50 steps"
tommy.walk(101);// "Are you serious? That's too far! I'm lazy"
Rich Mobile Apps with Sencha Touch
Part II – Class System

MIXINS
Sing

Performer

Play Instruments

Composer

Compose Songs

Singer-songwriter
Rich Mobile Apps with Sencha Touch
Part II – Class System

MIXINS
Ext.define('My.ability.Sing', {
sing: function(songName) {
alert('I`m singing ' + songName);
}
});
Ext.define('My.ability.PlayInstruments', {
play: function(instrument) {
alert('I`m playing ' + instrument);
}
});
Ext.define('My.ability.ComposeSongs', {
compose: function(songName) {
alert('I`m composing ' + songName);
}
});
Rich Mobile Apps with Sencha Touch
Part II – Class System

MIXINS
Ext.define('My.sample.Performer', {
extend: 'My.sample.Person',
mixins: {
canSing: 'My.ability.Sing',
canPlay: 'My.ability.PlayInstruments'
}
});
Ext.define('My.sample.Composer', {
extend: 'My.sample.Person',
mixins: {
canPlay: 'My.ability.PlayInstruments',
canCompose: 'My.ability.ComposeSongs'
}
});
Ext.define('My.sample.SingerSongwriter', {
extend: 'My.sample.Person',
mixins: {
canSing: 'My.ability.Sing',
canPlay: 'My.ability.PlayInstruments',
canCompose: 'My.ability.ComposeSongs'
}
});
Rich Mobile Apps with Sencha Touch
Part II – Class System

MIXINS
Ext.define('My.sample.Performer', {
extend: 'My.sample.Person',
mixins: {
canSing: 'My.ability.Sing',
canPlay: 'My.ability.PlayInstruments'
},
sing: function() {
alert("Here we go!");
this.mixins.canSing.sing.call(this);
alert("I`m done singing!");
}
});
var jamie = new My.sample.Performer('Jamie');
jamie.sing('Wind of Change'); // "Here we go!"
// "I`m singing Wind of Change"
// "I`m done singing!"
Rich Mobile Apps with Sencha Touch
Part II – Class System

Dependency Management
• Automatic Dependency Injection
<!-- ... -->
<head>
<!-- ... -->
<script src="ext.js"></script>
<script>
var tommy = Ext.create('My.sample.Developer','Tommy');
var jamie = Ext.create('My.sample.Performer','Jamie');
</script>
</head>
Rich Mobile Apps with Sencha Touch
Part II – Class System

Dependency Management
• Alternative
<!-- ... -->
<head>
<!-- ... -->
<script src="ext.js"></script>
<script>
Ext.require([
'My.sample.Developer',
'My.sample.Performer'
]);
Ext.onReady(function() {
var tommy = new My.sample.Developer('Tommy');
var jamie = new My.sample.Developer('Jamie');
});
</script>
</head>
<!-- ... -->
Rich Mobile Apps with Sencha Touch
Part II – Class System

Config
Ext.define('My.sample.Person', {
name: 'Anonymous',
age : 0,
gender: 'Male',
constructor: function(config) {
if (Ext.isObject(config)) {
if (config.hasOwnProperty('name')) {
this.setName(config.name);
}
if (config.hasOwnProperty('age')) {
this.setAge(config.age);
}
if (config.hasOwnProperty('gender')) {
this.setGender(config.gender);
}
}
}
});
Rich Mobile Apps with Sencha Touch
Part II – Class System

Config
/* ... */
setName: function(name) {
this.name = name;
return this;
},
getName: function() {
return this.name;
},
setAge: function(age) {
this.age = age;
return this;
},
getAge: function() {
return this.age;
},
/* ... */
Rich Mobile Apps with Sencha Touch
Part II – Class System

Config
Ext.define('My.sample.Person', {
config: {
name: 'Anonymous',
age : 0,
gender: 'Male'
},
constructor: function(config) {
this.initConfig(config);
}
});
var robert = new My.sample.Person({
name: 'Robert',
age: 21
})
robert.setName('Rob'); alert(robert.getAge()); //
robert.setAge(22); alert(robert.getAge());
//

"21"
"22"
Rich Mobile Apps with Sencha Touch
Part II – Class System

Config: Setter’s Process
Before

Set

After

• Validation
• Filtering
• Transformation

• Actual assignment

• Notification
• Updating dependencies
Rich Mobile Apps with Sencha Touch
Part II – Class System

Config: Magic Methods
Ext.define('My.sample.Person', {
/* ... */
applyAge: function(age) {
if (typeof age != 'number' || age < 0) {
alert("Invalid age, must be a positive number");
return;
}
return age;
},
updateAge: function(newAge, oldAge) {
alert("Age has changed from " + oldAge + " to " + newAge);
}
});
var aaron = new My.sample.Person({
name: "Aaron",
age: -100
}); // "Invalid age, must be a positive number"
alert(aaron.getAge());
alert(aaron.setAge(35));
alert(aaron.getAge());

// "0"
// "Age has changed from 0 to 35"
// "35"
Rich Mobile Apps with Sencha Touch
Part II – Class System

Q&A
Rich Mobile Apps with Sencha Touch
Part II – Class System

THANKS !!!

Mais conteúdo relacionado

Semelhante a Rich mobile apps with sencha touch - class system

Cross Platform Mobile App Development - An Introduction to Sencha Touch
Cross Platform Mobile App Development - An Introduction to Sencha TouchCross Platform Mobile App Development - An Introduction to Sencha Touch
Cross Platform Mobile App Development - An Introduction to Sencha TouchFolio3 Software
 
Appium understanding document
Appium understanding documentAppium understanding document
Appium understanding documentAkshay Pillay
 
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Innomatic Platform
 
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010Heiko Behrens
 
Iphone client-server app with Rails backend (v3)
Iphone client-server app with Rails backend (v3)Iphone client-server app with Rails backend (v3)
Iphone client-server app with Rails backend (v3)Sujee Maniyam
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.jsDavid Amend
 
Introduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile PlatformIntroduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile PlatformDominik Minta
 
Advanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to AndroidAdvanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to Androidsecurityxploded
 
Andriod dev toolbox part 2
Andriod dev toolbox  part 2Andriod dev toolbox  part 2
Andriod dev toolbox part 2Shem Magnezi
 
Introduction To Mobile-Automation
Introduction To Mobile-AutomationIntroduction To Mobile-Automation
Introduction To Mobile-AutomationMindfire Solutions
 
Advanced malware analysis training session8 introduction to android
Advanced malware analysis training session8 introduction to androidAdvanced malware analysis training session8 introduction to android
Advanced malware analysis training session8 introduction to androidCysinfo Cyber Security Community
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System RequirementsLaura Arrigo
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10Chris Schalk
 
SenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsSenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsMats Bryntse
 

Semelhante a Rich mobile apps with sencha touch - class system (20)

Cross Platform Mobile App Development - An Introduction to Sencha Touch
Cross Platform Mobile App Development - An Introduction to Sencha TouchCross Platform Mobile App Development - An Introduction to Sencha Touch
Cross Platform Mobile App Development - An Introduction to Sencha Touch
 
Sencha Touch MVC
Sencha Touch MVCSencha Touch MVC
Sencha Touch MVC
 
Sencha Cmd Quick Start
Sencha Cmd Quick StartSencha Cmd Quick Start
Sencha Cmd Quick Start
 
Appium understanding document
Appium understanding documentAppium understanding document
Appium understanding document
 
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
 
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
 
Iphone client-server app with Rails backend (v3)
Iphone client-server app with Rails backend (v3)Iphone client-server app with Rails backend (v3)
Iphone client-server app with Rails backend (v3)
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.js
 
Introduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile PlatformIntroduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile Platform
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Janus Mobile e-Seminar
Janus Mobile e-SeminarJanus Mobile e-Seminar
Janus Mobile e-Seminar
 
Advanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to AndroidAdvanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to Android
 
Andriod dev toolbox part 2
Andriod dev toolbox  part 2Andriod dev toolbox  part 2
Andriod dev toolbox part 2
 
Introduction To Mobile-Automation
Introduction To Mobile-AutomationIntroduction To Mobile-Automation
Introduction To Mobile-Automation
 
Advanced malware analysis training session8 introduction to android
Advanced malware analysis training session8 introduction to androidAdvanced malware analysis training session8 introduction to android
Advanced malware analysis training session8 introduction to android
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System Requirements
 
ExtJS framework
ExtJS frameworkExtJS framework
ExtJS framework
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10
 
SenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsSenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext js
 

Último

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 

Último (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 

Rich mobile apps with sencha touch - class system

  • 1. Rich Mobile Apps with Sencha Touch Part II – Class System
  • 2. Rich Mobile Apps with Sencha Touch Part II – Class System ExtJs And Sencha - 2 products that form the Sencha SDK. They are considered the best UI frameworks ever made for web applications. As we saw in the previous presentation they work cross platforms, cross browser but most importantly they deliver high quality and user experience that used to exist only in native applications. Best User Experience
  • 3. Rich Mobile Apps with Sencha Touch Part II – Class System Better Developer Experience
  • 4. Rich Mobile Apps with Sencha Touch Part II – Class System The Sencha Class System was first introduced in Ext JS 4.0 and was a major step forward in making it easy to build object oriented JavaScript code. As a core part of the Sencha JavaScript platform, it’s now a shared component between Ext JS and Sencha Touch 2. Ext JS and Sencha Touch 2 use the class system internally to manage dependencies, make code more reusable as well as provide a rich set of features that are commonly found in other class-based programming languages.
  • 5. Rich Mobile Apps with Sencha Touch Part II – Class System Class System Event System Data Package Widgets & Layouts …
  • 6. Rich Mobile Apps with Sencha Touch Part II – Class System Why do we call it a class system? Prototype-based Class-based
  • 7. Rich Mobile Apps with Sencha Touch Part II – Class System Flexibility Sencha Class System = Programmer Familiarity Predictability
  • 8. Rich Mobile Apps with Sencha Touch Part II – Class System Key Benefits Learn Develop • Consistent • Familiar • DRY • Debuggable • Testable • Automatic dependency resolution Deploy
  • 9. Rich Mobile Apps with Sencha Touch Part II – Class System Namespacing & Code Organization 1. OrganizationName.group[.subgroup].ClassName 2. One class per file 3. File name matches class name • Ext.chart.Label • Ext.data.writer.Xml • MyApp.field.Password  Ext/Chart/Label.js  Ext/data/writer/Xml.js  MyApp/field/Password.js
  • 10. Rich Mobile Apps with Sencha Touch Part II – Class System Class Definition Ext.define('My.sample.Person', { constructor: function(name) { this.name = name; }, walk: function(steps) { alert(this.name + ' is walking ' + steps + ' steps'); } });  Class definition is more than just inheritance var tommy = new My.sample.Person('Tommy');  Automatic namespace allocation tommy.walk(5); // alerts 'Tommy is walking 5 steps'  Classes are aware of their own names  Asynchronous vs. synchronous
  • 11. Rich Mobile Apps with Sencha Touch Part II – Class System Inheritance Ext.define('My.sample.Person', { constructor: function(name) { this.name = name; }, walk: function(steps) { alert(this.name + ' is walking ' + steps + ' steps'); } }); Ext.define('My.sample.Developer', { extend: 'My.sample.Person', code: function(language) { alert(this.name + ' is coding in ' + language); } }); var tommy = new My.sample.Developer('Tommy'); tommy.walk(5); // 'Tommy is walking 5 steps' tommy.code('JavaScript'); // 'Tommy is coding in JavaScript'
  • 12. Rich Mobile Apps with Sencha Touch Part II – Class System Inheritance Ext.define('My.sample.Developer', { extend: 'My.sample.Person', code: function(language) { alert(this.name + ' is coding in ' + language); }, walk: function(steps) { if (steps > 100) { alert('Are you serious? That`s too far! I`m lazy'); } else { return this.callParent(arguments); } } }); var tommy = new My.sample.Developer('Tommy'); tommy.walk(50); // "Tommy is walking 50 steps" tommy.walk(101);// "Are you serious? That's too far! I'm lazy"
  • 13. Rich Mobile Apps with Sencha Touch Part II – Class System MIXINS Sing Performer Play Instruments Composer Compose Songs Singer-songwriter
  • 14. Rich Mobile Apps with Sencha Touch Part II – Class System MIXINS Ext.define('My.ability.Sing', { sing: function(songName) { alert('I`m singing ' + songName); } }); Ext.define('My.ability.PlayInstruments', { play: function(instrument) { alert('I`m playing ' + instrument); } }); Ext.define('My.ability.ComposeSongs', { compose: function(songName) { alert('I`m composing ' + songName); } });
  • 15. Rich Mobile Apps with Sencha Touch Part II – Class System MIXINS Ext.define('My.sample.Performer', { extend: 'My.sample.Person', mixins: { canSing: 'My.ability.Sing', canPlay: 'My.ability.PlayInstruments' } }); Ext.define('My.sample.Composer', { extend: 'My.sample.Person', mixins: { canPlay: 'My.ability.PlayInstruments', canCompose: 'My.ability.ComposeSongs' } }); Ext.define('My.sample.SingerSongwriter', { extend: 'My.sample.Person', mixins: { canSing: 'My.ability.Sing', canPlay: 'My.ability.PlayInstruments', canCompose: 'My.ability.ComposeSongs' } });
  • 16. Rich Mobile Apps with Sencha Touch Part II – Class System MIXINS Ext.define('My.sample.Performer', { extend: 'My.sample.Person', mixins: { canSing: 'My.ability.Sing', canPlay: 'My.ability.PlayInstruments' }, sing: function() { alert("Here we go!"); this.mixins.canSing.sing.call(this); alert("I`m done singing!"); } }); var jamie = new My.sample.Performer('Jamie'); jamie.sing('Wind of Change'); // "Here we go!" // "I`m singing Wind of Change" // "I`m done singing!"
  • 17. Rich Mobile Apps with Sencha Touch Part II – Class System Dependency Management • Automatic Dependency Injection <!-- ... --> <head> <!-- ... --> <script src="ext.js"></script> <script> var tommy = Ext.create('My.sample.Developer','Tommy'); var jamie = Ext.create('My.sample.Performer','Jamie'); </script> </head>
  • 18. Rich Mobile Apps with Sencha Touch Part II – Class System Dependency Management • Alternative <!-- ... --> <head> <!-- ... --> <script src="ext.js"></script> <script> Ext.require([ 'My.sample.Developer', 'My.sample.Performer' ]); Ext.onReady(function() { var tommy = new My.sample.Developer('Tommy'); var jamie = new My.sample.Developer('Jamie'); }); </script> </head> <!-- ... -->
  • 19. Rich Mobile Apps with Sencha Touch Part II – Class System Config Ext.define('My.sample.Person', { name: 'Anonymous', age : 0, gender: 'Male', constructor: function(config) { if (Ext.isObject(config)) { if (config.hasOwnProperty('name')) { this.setName(config.name); } if (config.hasOwnProperty('age')) { this.setAge(config.age); } if (config.hasOwnProperty('gender')) { this.setGender(config.gender); } } } });
  • 20. Rich Mobile Apps with Sencha Touch Part II – Class System Config /* ... */ setName: function(name) { this.name = name; return this; }, getName: function() { return this.name; }, setAge: function(age) { this.age = age; return this; }, getAge: function() { return this.age; }, /* ... */
  • 21. Rich Mobile Apps with Sencha Touch Part II – Class System Config Ext.define('My.sample.Person', { config: { name: 'Anonymous', age : 0, gender: 'Male' }, constructor: function(config) { this.initConfig(config); } }); var robert = new My.sample.Person({ name: 'Robert', age: 21 }) robert.setName('Rob'); alert(robert.getAge()); // robert.setAge(22); alert(robert.getAge()); // "21" "22"
  • 22. Rich Mobile Apps with Sencha Touch Part II – Class System Config: Setter’s Process Before Set After • Validation • Filtering • Transformation • Actual assignment • Notification • Updating dependencies
  • 23. Rich Mobile Apps with Sencha Touch Part II – Class System Config: Magic Methods Ext.define('My.sample.Person', { /* ... */ applyAge: function(age) { if (typeof age != 'number' || age < 0) { alert("Invalid age, must be a positive number"); return; } return age; }, updateAge: function(newAge, oldAge) { alert("Age has changed from " + oldAge + " to " + newAge); } }); var aaron = new My.sample.Person({ name: "Aaron", age: -100 }); // "Invalid age, must be a positive number" alert(aaron.getAge()); alert(aaron.setAge(35)); alert(aaron.getAge()); // "0" // "Age has changed from 0 to 35" // "35"
  • 24. Rich Mobile Apps with Sencha Touch Part II – Class System Q&A
  • 25. Rich Mobile Apps with Sencha Touch Part II – Class System THANKS !!!