SlideShare una empresa de Scribd logo
1 de 40
JavaScript Design Patterns
Agenda
●
What ?
●
Types of Design Patterns
●
Some comman Anti-Patterns
●
Benefits and Disadvantages
●
Various Design Patterns
●
Design pattern are recurring solutions to software design
problems you find again and again in real-world application
development
●
Standardized solutions to common problems in software
design
What ?
Describes a bad solution to a particular problem which resulted in a bad
situation occurring
Examples of anti-patterns in JavaScript are the following:
 Polluting the global namespace by defining a large number of variables in
the global context
 Passing strings rather than functions to either setTimeout or setInterval as
this triggers the use of eval() internally.
 Modifying the Object class prototype (this is a particularly bad anti-pattern)
 Using JavaScript in an inline form as this is inflexible
 The use of document.write where native DOM alternatives such as
document.createElement are more appropriate.
Anti-Patterns
Benefits & Drawbacks
Benefits:
Design patterns enable large-scale reuse of software architectures
Patterns explicitly capture expert knowledge and design tradeoffs, and make
this expertise more widely available
Patterns help improve developer communication
Drawbacks:
Patterns do not lead to direct code reuse
Patterns are deceptively simple
Teams may suffer from pattern overload
Patterns are validated by experience and discussion rather than by automated
testing
Types of Pattern
Creational Patterns
concern the process of object creation.
Structural Patterns
concern with integration and composition of classes and objects.
Behavioral Patterns
concern with class or object communication.
CREATIONAL
PATTERNS
Factory Method
Abstract Factory
Builder
Prototype
Singleton
STRUCTURAL
PATTERNS
Adapter
Bridge
Composite
Decorator
Façade
Flyweight
Proxy
BEHAVIORAL
PATTERNS
Chain of Responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observer
State
Strategy
Template Method
Visitor
Modern Day Patterns
 The Module Pattern
 The Revealing Module Pattern
 The Singleton Pattern
 The Observer Pattern
 The Mediator Pattern
 The Prototype Pattern
 The Facade Pattern
 The Factory Pattern
Module Design Pattern
Focuses on public and private access to methods & variables.
Demo
Advantages
Cleaner approach for developers
Supports private data
Less clutter in the global namespace
Localization of functions and variables through closures
Disadvantages
Private methods are unaccessible, some people say that this leads
to the inability of unit testing
Private methods and functions lose extendability since they are
unaccessible (see my comment in the previous bullet point).
Revealing Module Design Pattern
Same as Module Pattern, the only difference is that it was
engineered as a way to ensure that all methods and variables are
kept private until they are explicitly exposed; usually through an
object literal returned by the closure from which it’s defined.
Demo
Advantages
Cleaner approach for developers
Supports private data
Less clutter in the global namespace
Localization of functions and variables through closures
The syntax of our scripts are even more consistent
Explicitly defined public methods and variables which lead to increased
readability
Disadvantages
Same as Module Pattern
Singleton Design Pattern
Restricts instantiation of an object to a single reference
Demo
Advantages
Reduced memory footprint
Single point of access
Delayed initialization that prevents instantiation until required
Disadvantages
Once instantiated, they’re hardly ever “reset”.
Harder to unit test and sometimes introduces hidden dependencies.
Prototype Design Pattern
Prototype Design Pattern
The prototype pattern focuses on creating an object that can be used as a
blueprint for other objects through prototypal inheritance.
Demo
Advantages
New objects created from the “skeleton” of an existing object inherit references
to existing functions on the prototype chain, thus boosting performance and
keeping memory footprints to a minimum.
Great for an application where the focus is on object creation
Disadvantages
Overkill for a project that uses very few objects and/or does not have an
underlying emphasis on the extension of prototype chains
Factory Design Pattern
Provides an interface for developers to create new objects through
the use of the factory rather than invoking the new operator on an
object.
Demo
Advantages
The Factory pattern can be especially useful when applied to the following
situations:
 When your object's setup requires a high level of complexity
 When you need to generate different instances depending on the
environment
 When you're working with many small objects that share the same
properties or need to create components that require similar instantiation
or methods
 Great for decoupling components.
Disadvantages
Add an unnecessarily additional aspect of complexity to code.
Unit testing can be difficult as a direct result of the object creation process
being hidden by the factory methods.
Facade Design Pattern
Conceal the underlying complexity of the code by using an anonymous
function as an extra layer.
Extremely interesting and very useful for adding an extra layer of security to
your already minified code.
Extremely useful when coupled with the revealing module pattern.
Demo
Advantages
Enhances security for your web application
Works well in combination with other patterns
Easy to implement
Makes it easy to patch internals
Provides a simpler public interface
Proven useful for other major libraries such as jQuery
Disadvantages
One possible note worth mentioning is that a developer must decide whether the implicit
cost of implementation is really worth the abstraction (though this is generally a small
footprint).
Observer Design Pattern
This pattern implements a single object (the subject) that maintains a
reference to a collection of objects (known as “observers”) and broadcasts
notifications when a change to state occurs.
Demo
Advantages
Requires deeper-level thinking of the relationship between the various
components of an application
Helps us pinpoint dependencies
Excellent at decoupling objects which often promotes smaller, reusable
components
Dynamic relationships may exist between publishers and subscribers when
using this pattern. This provides a great deal of flexibility which may not be as
easy to implement when disparate parts of your application are tightly coupled.
Disadvantages
Checking the integrity of your application can become difficult.
Switching a subscriber from one publisher to another can be costly.
For reference
http://carldanley.com/javascript-design-patterns/
http://addyosmani.com/resources/essentialjsdesignpatterns/book
Questions ?

Más contenido relacionado

La actualidad más candente

How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsAndy Maleh
 
Factory Method Design Pattern
Factory Method Design PatternFactory Method Design Pattern
Factory Method Design Patternmelbournepatterns
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Steven Smith
 
Unit vs. Integration Tests
Unit vs. Integration TestsUnit vs. Integration Tests
Unit vs. Integration TestsDavid Völkel
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowRachid Kherrazi
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Sameer Rathoud
 
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
 

La actualidad más candente (11)

How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design Patterns
 
Factory Method Design Pattern
Factory Method Design PatternFactory Method Design Pattern
Factory Method Design Pattern
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Unit vs. Integration Tests
Unit vs. Integration TestsUnit vs. Integration Tests
Unit vs. Integration Tests
 
Android MVVM
Android MVVMAndroid MVVM
Android MVVM
 
Factory method pattern
Factory method patternFactory method pattern
Factory method pattern
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
 
Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)
 
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
 

Similar a Design pattern

P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patternssukumarraju6
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsJason Townsend, MBA
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternsbonej010
 
Александр Белецкий "Архитектура Javascript приложений"
 Александр Белецкий "Архитектура Javascript приложений" Александр Белецкий "Архитектура Javascript приложений"
Александр Белецкий "Архитектура Javascript приложений"Agile Base Camp
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Kevin Schultz
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxanguraju1
 
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
 
Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript AppsGil Fink
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Steven Smith
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure rupeshchanchal
 

Similar a Design pattern (20)

P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Александр Белецкий "Архитектура Javascript приложений"
 Александр Белецкий "Архитектура Javascript приложений" Александр Белецкий "Архитектура Javascript приложений"
Александр Белецкий "Архитектура Javascript приложений"
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Dtacs
DtacsDtacs
Dtacs
 
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
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript Apps
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 

Último

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Último (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Design pattern

  • 2. Agenda ● What ? ● Types of Design Patterns ● Some comman Anti-Patterns ● Benefits and Disadvantages ● Various Design Patterns
  • 3. ● Design pattern are recurring solutions to software design problems you find again and again in real-world application development ● Standardized solutions to common problems in software design What ?
  • 4. Describes a bad solution to a particular problem which resulted in a bad situation occurring Examples of anti-patterns in JavaScript are the following:  Polluting the global namespace by defining a large number of variables in the global context  Passing strings rather than functions to either setTimeout or setInterval as this triggers the use of eval() internally.  Modifying the Object class prototype (this is a particularly bad anti-pattern)  Using JavaScript in an inline form as this is inflexible  The use of document.write where native DOM alternatives such as document.createElement are more appropriate. Anti-Patterns
  • 5. Benefits & Drawbacks Benefits: Design patterns enable large-scale reuse of software architectures Patterns explicitly capture expert knowledge and design tradeoffs, and make this expertise more widely available Patterns help improve developer communication Drawbacks: Patterns do not lead to direct code reuse Patterns are deceptively simple Teams may suffer from pattern overload Patterns are validated by experience and discussion rather than by automated testing
  • 7. Creational Patterns concern the process of object creation. Structural Patterns concern with integration and composition of classes and objects. Behavioral Patterns concern with class or object communication.
  • 9. Modern Day Patterns  The Module Pattern  The Revealing Module Pattern  The Singleton Pattern  The Observer Pattern  The Mediator Pattern  The Prototype Pattern  The Facade Pattern  The Factory Pattern
  • 10. Module Design Pattern Focuses on public and private access to methods & variables.
  • 11. Demo
  • 12. Advantages Cleaner approach for developers Supports private data Less clutter in the global namespace Localization of functions and variables through closures
  • 13. Disadvantages Private methods are unaccessible, some people say that this leads to the inability of unit testing Private methods and functions lose extendability since they are unaccessible (see my comment in the previous bullet point).
  • 14. Revealing Module Design Pattern Same as Module Pattern, the only difference is that it was engineered as a way to ensure that all methods and variables are kept private until they are explicitly exposed; usually through an object literal returned by the closure from which it’s defined.
  • 15. Demo
  • 16. Advantages Cleaner approach for developers Supports private data Less clutter in the global namespace Localization of functions and variables through closures The syntax of our scripts are even more consistent Explicitly defined public methods and variables which lead to increased readability
  • 18. Singleton Design Pattern Restricts instantiation of an object to a single reference
  • 19. Demo
  • 20. Advantages Reduced memory footprint Single point of access Delayed initialization that prevents instantiation until required
  • 21. Disadvantages Once instantiated, they’re hardly ever “reset”. Harder to unit test and sometimes introduces hidden dependencies.
  • 23. Prototype Design Pattern The prototype pattern focuses on creating an object that can be used as a blueprint for other objects through prototypal inheritance.
  • 24. Demo
  • 25. Advantages New objects created from the “skeleton” of an existing object inherit references to existing functions on the prototype chain, thus boosting performance and keeping memory footprints to a minimum. Great for an application where the focus is on object creation
  • 26. Disadvantages Overkill for a project that uses very few objects and/or does not have an underlying emphasis on the extension of prototype chains
  • 27. Factory Design Pattern Provides an interface for developers to create new objects through the use of the factory rather than invoking the new operator on an object.
  • 28. Demo
  • 29. Advantages The Factory pattern can be especially useful when applied to the following situations:  When your object's setup requires a high level of complexity  When you need to generate different instances depending on the environment  When you're working with many small objects that share the same properties or need to create components that require similar instantiation or methods  Great for decoupling components.
  • 30. Disadvantages Add an unnecessarily additional aspect of complexity to code. Unit testing can be difficult as a direct result of the object creation process being hidden by the factory methods.
  • 31. Facade Design Pattern Conceal the underlying complexity of the code by using an anonymous function as an extra layer. Extremely interesting and very useful for adding an extra layer of security to your already minified code. Extremely useful when coupled with the revealing module pattern.
  • 32. Demo
  • 33. Advantages Enhances security for your web application Works well in combination with other patterns Easy to implement Makes it easy to patch internals Provides a simpler public interface Proven useful for other major libraries such as jQuery
  • 34. Disadvantages One possible note worth mentioning is that a developer must decide whether the implicit cost of implementation is really worth the abstraction (though this is generally a small footprint).
  • 35. Observer Design Pattern This pattern implements a single object (the subject) that maintains a reference to a collection of objects (known as “observers”) and broadcasts notifications when a change to state occurs.
  • 36. Demo
  • 37. Advantages Requires deeper-level thinking of the relationship between the various components of an application Helps us pinpoint dependencies Excellent at decoupling objects which often promotes smaller, reusable components Dynamic relationships may exist between publishers and subscribers when using this pattern. This provides a great deal of flexibility which may not be as easy to implement when disparate parts of your application are tightly coupled.
  • 38. Disadvantages Checking the integrity of your application can become difficult. Switching a subscriber from one publisher to another can be costly.