SlideShare una empresa de Scribd logo
1 de 48
Descargar para leer sin conexión
Addy Osmani
Introduction


   This talk will cover strategies that can help
   streamline your application architecture.
   Thanks to Nicholas Zakas, Rebecca
   Murphey, Paul Irish and Justin Meyer for their
   previous work in this area.
What is a ‘large’ application?

  Some developers suggested:

    “Apps where the size of code is
    over over 100,000 LOC”
    Incorrect, because code size does
    not always correlate to complexity
What is a ‘large’ application?


   “Apps with over 1MB of JS code
   written in-house”
   Again, this could be very simplistic
   code. Can we get more clear?
What is a ‘large’ application?


   “A non-trivial application
   requiring significant developer
   effort to maintain”
   Correct.
SOME EXAMPLES




         GMail
SOME EXAMPLES




      Yahoo! Homepage
SOME EXAMPLES




        MobileMe
SOME EXAMPLES




      Aol Mail / Phoenix
Your Architecture
Your current architecture likely resembles a mixture of the following:


                        Custom Widgets

                             Modules

                        Application Core

              MVC (Models/Views/Controllers)

               JavaScript Libraries & Toolkits
Possible problems with this:


 How much of this architecture is instantly re-usable?
 Can single modules exist on their own independently?
 Are they self-contained?
Possible problems with this:


 How much do modules depend on other modules
 inside the same system?
 Does your app contain many modules that are tightly
 coupled?
Possible problems with this:


 How easily can you test individual modules?
 How certain are you that if specific parts of your
 application fail, it can still function?
Think long-term


Developers often couple their DOM manipulation code
quite tightly with the rest of their application
Why is this not a good idea if we’re thinking long-term?
Think long-term


You may decide to switch from using jQuery to Dojo or
YUI for reasons of performance, security or design.
Can this decision currently be made without rewriting
your entire application?
Remember..


“The secret to building large apps is never build large
apps. Break your applications into small pieces. Then,
assemble those testable, bite-sized pieces into your
big application” - Justin Meyer.
Also..


 “The more tied components are to each other, the less
 reusable they will be, and the more difficult it
 becomes to make changes to one without accidentally
 affecting another” - Rebecca Murphey.
Let’s brainstorm.

 We want a loosely coupled architecture with
 functionality broken down into smaller modules that
 aren’t dependant on one another.
 You probably already use modules but we need them
 to be fully independent entities.
Some more ideas.

To achieve this we need single modules to speak to
the rest of the application when something interesting
happens.
We then use a different layer to interpret requests so
that modules don’t directly access the core.
This aids in preventing applications from falling over
due to errors with a specific module.
and wrapping up..

Modules shouldn’t be able to access everything.
They probably can in most current architectures.
Having an intermediate layer handle permissions for
which modules can access which parts of your
framework gives you a layer of security.
This means a module is only able to do at most what
we’ve permitted it do.
Solution

 Module theory +
 Facade pattern +
 Mediator pattern
 = WIN
Module Theory


 “Anything can be defined as a reusable module”
 - Zakas.
 Modules should be considered independent units
 of functionality that can exist on their own
Module Theory


 Modules have very limited knowledge of what’s
 going on in the rest of the application
 Loose coupling is essential to this - modules
 should ideally not depend on other modules.
Loose Coupling

Facilitates improved maintainability by removing code
dependencies where possible
In our case, modules should not rely on other modules
in order to function correctly.
When used effectively, it’s straight-forward to see
how changes to one part of a system may affect
another.
Applying Module Theory

Any significantly non-trivial application should be built
from modular components
When a module is reusable it’s clear how to use or
extend it
In JavaScript, there are several options for defining
modules, including:
The Module Pattern

The well-known module pattern makes use of
closures to bake privacy, state and organization into
your objects.
It’s quite similar to an IIFE with an object returned
instead of a function.
Commonly implemented as a singleton.
Object Literals

 Object literal notation is another option for
 structuring modules
 Basically consists of an array of key:value pairs
 Methods defined using object literal notation don’t exist
 until the execution of the script.
Facade Pattern

  Provides a convenient higher-level interface to a
  larger body of code, regardless of underlying
  complexity
  Hides the inner-workings of a library or set of
  modules, allowing the implementation to be less
  important.
  We thus only need to interact with the facade
  rather than the subsystem it encompasses.
The Mediator Pattern


Encapsulates how disparate modules interact with
each other by acting as an intermediary
Promotes loose coupling by preventing objects from
referring to each other explicitly, solving our module
inter-dependency issues.
The Mediator Pattern


Allows for actions of each module to vary
independently, so it’s extremely flexible
Somewhat similar to Observer/Pub-Sub, so it’s not
difficult to understand how it fits in if you’ve used one of
these patterns previously.
Why is it the bee’s knees?


 Allows modules to broadcast or listen for messages
 without worrying about the rest of the system
 Messages can be handled by any number of modules
 at once.
 Typically significantly more easy to add or remove
 features to systems which are loosely coupled like this.
Mediator downsides

By adding a mediator between modules, they must
always communicate indirectly. This can cause a very
minor performance drop.
Because of the nature of loose coupling, it’s difficult to
establish how a system might react by only looking at
the broadcasts.
At the end of the day, tight coupling causes all kinds of
headaches and this is one solution.
Mediator Metaphor

  Think of an airport control tower. The tower
  handles what planes can take off and land.
  All communications are done from the planes to
  the control tower, rather than from plane-to-
  plane
  A centralised controller is key to the success of
  this system as is the case with the mediator
  pattern.
The Facade

Effectively, an abstraction of the application core that
sits in the middle between it and modules
Ensures a consistent interface to our modules is
available at all times
Should be the only thing modules are aware of - they
shouldn’t know about other components.
The Facade

Components communicate via the adapter so it needs
to be dependable
The adapter acts as a security guard, determining
which parts of the application a module can access
Components only call their own methods and
shouldn’t interact with anything they don’t have
permission to
NOTE:

Nicholas Zakas refers to the facade here as a sandbox
controller.
Agrees that it could equally be considered the adapter,
proxy or facade pattern.
As Stoyan Stefanov defined an existing ‘sandbox’
pattern, I refer to the sandbox as a facade as IMO this
pattern matches it’s purpose most closely.
The application core

 It’s job is to manage the module lifecycle.
 When is it safe for a module to start?
 When should it stop?
 Modules should execute automatically when started.
The application core

 It’s not the core’s job to decide whether this should be
 when the DOM is ready.
 The core should enable adding or removing modules
 without breaking anything.
 It should ideally also handle detecting and managing
 errors in the system.
Revised Architecture
      •     Your new architecture could potentially look something like this:

                                       Publishers

Libraries                   Self-contained modules

                      Adapter (abstraction of the core)              Mediation
      Subscribers
                          Application Core (Mediator)
                          tied into MVC if using that
                                    pattern.
Tying in: modules

 Modules want to inform the application when
 something interesting happens. eg. a new message
 has arrived.other modules related as necessary.
 Correctly publishing events of interest should be their
 primary concern.
Tying in: the facade


 The core (via the abstracted adapter) listens out for
 interesting events and says ‘Awesome. What
 happened? Give me the details’.
Tying in: the core



 The core will then react/start or stop other modules
 related as necessary.
Modules


 Should ideally not be concerned about:
   what objects or modules are being notified
   where these objects are based (client? server?)
   how many objects subscribe to notification
Module Communication
                                              ‘Tom’s order has been
                                              successfully packaged
            Module 1
          OrderPackager
                                                                                  Adapter
 notify(‘orderPackaged’,‘Tom’,‘success’)                                  M
                                              Start LabelManager
                                                                                   Core
             Module 2
           LabelManager                       ‘Tom’s order has been
                                                      labelled
  notify(‘orderLabelled’,‘Tom’, ‘success’)
                                                                 Start DispatchManager
            Module 3
        DispatchManager                       ‘Tom’s order has been
                                                    dispatched
notify(‘orderDispatched’,‘Tom’, ‘success’,’12-08-11’)
Summary

 The core acts as like a ‘Pub/Sub’ manager using
 the mediator pattern. Responsible for module
 management.
 The facade abstracts the core to avoid modules
 touching it directly. Handles security.
 The modules contain specific pieces of
 functionality for your application.
Result


Modules are no longer dependent on anyone.
If you stick to a consistent API, you can easily replace
a module using jQuery with one using dojo later on.
Result


Modules can be easily tested and maintained on
their own.
Modules can be added or removed without the
application falling over.

Más contenido relacionado

La actualidad más candente

Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery維佋 唐
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface ComponentsAhmad Hamid
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module PatternsNicholas Jansma
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2kaven yan
 
Design Patterns in iOS
Design Patterns in iOSDesign Patterns in iOS
Design Patterns in iOSYi-Shou Chen
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiJared Faris
 
Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaLXMetaL
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsLalit Kale
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from ScratchUdaya Kumar
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
Lecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsLecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsMaksym Davydov
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa TouchEliah Nikans
 
Building a JavaScript Module Framework at Gilt
Building a JavaScript Module Framework at GiltBuilding a JavaScript Module Framework at Gilt
Building a JavaScript Module Framework at GiltEric Shepherd
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkAkhil Mittal
 

La actualidad más candente (20)

Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface Components
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
Design Patterns in iOS
Design Patterns in iOSDesign Patterns in iOS
Design Patterns in iOS
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
Knockout in action
Knockout in actionKnockout in action
Knockout in action
 
Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaL
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from Scratch
 
Extjs
ExtjsExtjs
Extjs
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
Lecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsLecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile Apps
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa Touch
 
Building a JavaScript Module Framework at Gilt
Building a JavaScript Module Framework at GiltBuilding a JavaScript Module Framework at Gilt
Building a JavaScript Module Framework at Gilt
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
 
5 angularjs features
5 angularjs features5 angularjs features
5 angularjs features
 

Destacado

Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design PatternsAddy Osmani
 
Open-source Mic Talks at AOL
Open-source Mic Talks at AOLOpen-source Mic Talks at AOL
Open-source Mic Talks at AOLAddy Osmani
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsVolodymyr Voytyshyn
 
Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureNicholas Zakas
 
So what's a web app? introduction to the chrome web store
So what's a web app? introduction to the chrome web storeSo what's a web app? introduction to the chrome web store
So what's a web app? introduction to the chrome web storeEric Bidelman
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applicationsMilan Korsos
 
Unchallengeable miracle of Holy Quran
Unchallengeable miracle of  Holy QuranUnchallengeable miracle of  Holy Quran
Unchallengeable miracle of Holy Quranyoursincerefriend
 
An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3Event Handler
 
Java Script
Java ScriptJava Script
Java Scriptsiddaram
 
Introduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoIntroduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoEvent Handler
 
8. java script
8. java script8. java script
8. java scriptAnusAhmad
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup EmpireThe Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup EmpireSeh Hui Leong
 
The big bang theory - UNIT 2
The big bang theory - UNIT 2The big bang theory - UNIT 2
The big bang theory - UNIT 2lm092068
 
The big bang theory of social recruiting
The big bang theory of social recruitingThe big bang theory of social recruiting
The big bang theory of social recruitingFastCollab
 
An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5Event Handler
 
An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4Event Handler
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPTGo4Guru
 
An Introduction to JavaScript: Week One
An Introduction to JavaScript: Week OneAn Introduction to JavaScript: Week One
An Introduction to JavaScript: Week OneEvent Handler
 

Destacado (20)

Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design Patterns
 
Open-source Mic Talks at AOL
Open-source Mic Talks at AOLOpen-source Mic Talks at AOL
Open-source Mic Talks at AOL
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
 
Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application Architecture
 
So what's a web app? introduction to the chrome web store
So what's a web app? introduction to the chrome web storeSo what's a web app? introduction to the chrome web store
So what's a web app? introduction to the chrome web store
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applications
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Unchallengeable miracle of Holy Quran
Unchallengeable miracle of  Holy QuranUnchallengeable miracle of  Holy Quran
Unchallengeable miracle of Holy Quran
 
An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3
 
Java Script
Java ScriptJava Script
Java Script
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
 
Introduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoIntroduction to JavaScript: Week Two
Introduction to JavaScript: Week Two
 
8. java script
8. java script8. java script
8. java script
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup EmpireThe Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
 
The big bang theory - UNIT 2
The big bang theory - UNIT 2The big bang theory - UNIT 2
The big bang theory - UNIT 2
 
The big bang theory of social recruiting
The big bang theory of social recruitingThe big bang theory of social recruiting
The big bang theory of social recruiting
 
An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5
 
An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
An Introduction to JavaScript: Week One
An Introduction to JavaScript: Week OneAn Introduction to JavaScript: Week One
An Introduction to JavaScript: Week One
 

Similar a Large-Scale JavaScript Development

Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignIrwansyah Irwansyah
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endSaeid Zebardast
 
Structured Software Design
Structured Software DesignStructured Software Design
Structured Software DesignGiorgio Zoppi
 
Introduction To MVVM
Introduction To MVVMIntroduction To MVVM
Introduction To MVVMBoulos Dib
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
Microservice architecture : Part 1
Microservice architecture : Part 1Microservice architecture : Part 1
Microservice architecture : Part 1NodeXperts
 
Marionette - TorontoJS
Marionette - TorontoJSMarionette - TorontoJS
Marionette - TorontoJSmatt-briggs
 
Tech challenges in a large scale agile project
Tech challenges in a large scale agile projectTech challenges in a large scale agile project
Tech challenges in a large scale agile projectHarald Soevik
 
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai..."Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...Fwdays
 
Marionette structure with modules
Marionette structure with modulesMarionette structure with modules
Marionette structure with modulesmatt-briggs
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desaijinaldesailive
 
Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Mathew Beane
 
Android Dagger 2
Android  Dagger 2Android  Dagger 2
Android Dagger 2Sanket Shah
 
Over view of software artitecture
Over view of software artitectureOver view of software artitecture
Over view of software artitectureABDEL RAHMAN KARIM
 

Similar a Large-Scale JavaScript Development (20)

Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-end
 
Structured Software Design
Structured Software DesignStructured Software Design
Structured Software Design
 
Introduction To MVVM
Introduction To MVVMIntroduction To MVVM
Introduction To MVVM
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity Framework
 
Microservice architecture : Part 1
Microservice architecture : Part 1Microservice architecture : Part 1
Microservice architecture : Part 1
 
PureMVC
PureMVCPureMVC
PureMVC
 
Marionette - TorontoJS
Marionette - TorontoJSMarionette - TorontoJS
Marionette - TorontoJS
 
Tech challenges in a large scale agile project
Tech challenges in a large scale agile projectTech challenges in a large scale agile project
Tech challenges in a large scale agile project
 
Breaking the monolith
Breaking the monolithBreaking the monolith
Breaking the monolith
 
Design patterns
Design patternsDesign patterns
Design patterns
 
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai..."Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
 
Marionette structure with modules
Marionette structure with modulesMarionette structure with modules
Marionette structure with modules
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
Metasploit
MetasploitMetasploit
Metasploit
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2
 
Android Dagger 2
Android  Dagger 2Android  Dagger 2
Android Dagger 2
 
Over view of software artitecture
Over view of software artitectureOver view of software artitecture
Over view of software artitecture
 

Último

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Large-Scale JavaScript Development

  • 2. Introduction This talk will cover strategies that can help streamline your application architecture. Thanks to Nicholas Zakas, Rebecca Murphey, Paul Irish and Justin Meyer for their previous work in this area.
  • 3. What is a ‘large’ application? Some developers suggested: “Apps where the size of code is over over 100,000 LOC” Incorrect, because code size does not always correlate to complexity
  • 4. What is a ‘large’ application? “Apps with over 1MB of JS code written in-house” Again, this could be very simplistic code. Can we get more clear?
  • 5. What is a ‘large’ application? “A non-trivial application requiring significant developer effort to maintain” Correct.
  • 7. SOME EXAMPLES Yahoo! Homepage
  • 8. SOME EXAMPLES MobileMe
  • 9. SOME EXAMPLES Aol Mail / Phoenix
  • 10.
  • 11. Your Architecture Your current architecture likely resembles a mixture of the following: Custom Widgets Modules Application Core MVC (Models/Views/Controllers) JavaScript Libraries & Toolkits
  • 12. Possible problems with this: How much of this architecture is instantly re-usable? Can single modules exist on their own independently? Are they self-contained?
  • 13. Possible problems with this: How much do modules depend on other modules inside the same system? Does your app contain many modules that are tightly coupled?
  • 14. Possible problems with this: How easily can you test individual modules? How certain are you that if specific parts of your application fail, it can still function?
  • 15. Think long-term Developers often couple their DOM manipulation code quite tightly with the rest of their application Why is this not a good idea if we’re thinking long-term?
  • 16. Think long-term You may decide to switch from using jQuery to Dojo or YUI for reasons of performance, security or design. Can this decision currently be made without rewriting your entire application?
  • 17. Remember.. “The secret to building large apps is never build large apps. Break your applications into small pieces. Then, assemble those testable, bite-sized pieces into your big application” - Justin Meyer.
  • 18. Also.. “The more tied components are to each other, the less reusable they will be, and the more difficult it becomes to make changes to one without accidentally affecting another” - Rebecca Murphey.
  • 19. Let’s brainstorm. We want a loosely coupled architecture with functionality broken down into smaller modules that aren’t dependant on one another. You probably already use modules but we need them to be fully independent entities.
  • 20. Some more ideas. To achieve this we need single modules to speak to the rest of the application when something interesting happens. We then use a different layer to interpret requests so that modules don’t directly access the core. This aids in preventing applications from falling over due to errors with a specific module.
  • 21. and wrapping up.. Modules shouldn’t be able to access everything. They probably can in most current architectures. Having an intermediate layer handle permissions for which modules can access which parts of your framework gives you a layer of security. This means a module is only able to do at most what we’ve permitted it do.
  • 22. Solution Module theory + Facade pattern + Mediator pattern = WIN
  • 23. Module Theory “Anything can be defined as a reusable module” - Zakas. Modules should be considered independent units of functionality that can exist on their own
  • 24. Module Theory Modules have very limited knowledge of what’s going on in the rest of the application Loose coupling is essential to this - modules should ideally not depend on other modules.
  • 25. Loose Coupling Facilitates improved maintainability by removing code dependencies where possible In our case, modules should not rely on other modules in order to function correctly. When used effectively, it’s straight-forward to see how changes to one part of a system may affect another.
  • 26. Applying Module Theory Any significantly non-trivial application should be built from modular components When a module is reusable it’s clear how to use or extend it In JavaScript, there are several options for defining modules, including:
  • 27. The Module Pattern The well-known module pattern makes use of closures to bake privacy, state and organization into your objects. It’s quite similar to an IIFE with an object returned instead of a function. Commonly implemented as a singleton.
  • 28. Object Literals Object literal notation is another option for structuring modules Basically consists of an array of key:value pairs Methods defined using object literal notation don’t exist until the execution of the script.
  • 29. Facade Pattern Provides a convenient higher-level interface to a larger body of code, regardless of underlying complexity Hides the inner-workings of a library or set of modules, allowing the implementation to be less important. We thus only need to interact with the facade rather than the subsystem it encompasses.
  • 30. The Mediator Pattern Encapsulates how disparate modules interact with each other by acting as an intermediary Promotes loose coupling by preventing objects from referring to each other explicitly, solving our module inter-dependency issues.
  • 31. The Mediator Pattern Allows for actions of each module to vary independently, so it’s extremely flexible Somewhat similar to Observer/Pub-Sub, so it’s not difficult to understand how it fits in if you’ve used one of these patterns previously.
  • 32. Why is it the bee’s knees? Allows modules to broadcast or listen for messages without worrying about the rest of the system Messages can be handled by any number of modules at once. Typically significantly more easy to add or remove features to systems which are loosely coupled like this.
  • 33. Mediator downsides By adding a mediator between modules, they must always communicate indirectly. This can cause a very minor performance drop. Because of the nature of loose coupling, it’s difficult to establish how a system might react by only looking at the broadcasts. At the end of the day, tight coupling causes all kinds of headaches and this is one solution.
  • 34. Mediator Metaphor Think of an airport control tower. The tower handles what planes can take off and land. All communications are done from the planes to the control tower, rather than from plane-to- plane A centralised controller is key to the success of this system as is the case with the mediator pattern.
  • 35. The Facade Effectively, an abstraction of the application core that sits in the middle between it and modules Ensures a consistent interface to our modules is available at all times Should be the only thing modules are aware of - they shouldn’t know about other components.
  • 36. The Facade Components communicate via the adapter so it needs to be dependable The adapter acts as a security guard, determining which parts of the application a module can access Components only call their own methods and shouldn’t interact with anything they don’t have permission to
  • 37. NOTE: Nicholas Zakas refers to the facade here as a sandbox controller. Agrees that it could equally be considered the adapter, proxy or facade pattern. As Stoyan Stefanov defined an existing ‘sandbox’ pattern, I refer to the sandbox as a facade as IMO this pattern matches it’s purpose most closely.
  • 38. The application core It’s job is to manage the module lifecycle. When is it safe for a module to start? When should it stop? Modules should execute automatically when started.
  • 39. The application core It’s not the core’s job to decide whether this should be when the DOM is ready. The core should enable adding or removing modules without breaking anything. It should ideally also handle detecting and managing errors in the system.
  • 40. Revised Architecture • Your new architecture could potentially look something like this: Publishers Libraries Self-contained modules Adapter (abstraction of the core) Mediation Subscribers Application Core (Mediator) tied into MVC if using that pattern.
  • 41. Tying in: modules Modules want to inform the application when something interesting happens. eg. a new message has arrived.other modules related as necessary. Correctly publishing events of interest should be their primary concern.
  • 42. Tying in: the facade The core (via the abstracted adapter) listens out for interesting events and says ‘Awesome. What happened? Give me the details’.
  • 43. Tying in: the core The core will then react/start or stop other modules related as necessary.
  • 44. Modules Should ideally not be concerned about: what objects or modules are being notified where these objects are based (client? server?) how many objects subscribe to notification
  • 45. Module Communication ‘Tom’s order has been successfully packaged Module 1 OrderPackager Adapter notify(‘orderPackaged’,‘Tom’,‘success’) M Start LabelManager Core Module 2 LabelManager ‘Tom’s order has been labelled notify(‘orderLabelled’,‘Tom’, ‘success’) Start DispatchManager Module 3 DispatchManager ‘Tom’s order has been dispatched notify(‘orderDispatched’,‘Tom’, ‘success’,’12-08-11’)
  • 46. Summary The core acts as like a ‘Pub/Sub’ manager using the mediator pattern. Responsible for module management. The facade abstracts the core to avoid modules touching it directly. Handles security. The modules contain specific pieces of functionality for your application.
  • 47. Result Modules are no longer dependent on anyone. If you stick to a consistent API, you can easily replace a module using jQuery with one using dojo later on.
  • 48. Result Modules can be easily tested and maintained on their own. Modules can be added or removed without the application falling over.