SlideShare a Scribd company logo
NodeJS : Design Patterns
27 Feb 2021
Acknowledgements
• Organising team
• O.P. Pachoriya & Sanny Kumar from Talentica.
2
Agenda
• What are design patterns?
• Creational design patterns
• Singleton Pattern
• Prototype Pattern
• Factory Method Pattern
• Builder Pattern
3
Agenda contd.
• Behavioural design patterns
• The chain of responsibility pattern
• The command pattern
• The iterator pattern
• The observer pattern
• The strategy pattern
4
What should you know
• Understanding of JavaScript
• Some working knowledge with Node.js
• Experience working in Object Oriented
Programming environment
5
Procedural Programming
6
f() x
x
f()
Program
f()
f()
f()
f()
f()
f()
f()
f()
OOP (A brush up)
7
f() x
f() x
Properties
Methods
Object
8
OOP Benefits
9
• Encapsulation: Helps reduce complexity & promotes reusability
• Abstraction: Reduces complexity & isolates impact of changes
• Inheritance: Eliminates redundant code
• Polymorphism: Promotes refactoring of long if/else, switch/case
statements
What are design patterns?
Reusable, reliable solutions to problem that we face
every day in software development
10
Why Design Patterns?
• Cataloged solutions
• Reusable in many different situations
• Well documented
• Language for collaboration
• Improve architecture
• Write better program
• Become a better programmer
11
Gang of Four (GoF)
• Elements of Reusable Object-Oriented Software
- Gang of Four, 1994
• Design Patterns definition
• Pattern name
• The problem
• The solution
• Consequences
12
Classical design patterns
13
Creational
These patterns have to do with
class instantiation, the creation of
object instances in our applications
Structural
Structural design patterns have to
do with the way objects are
composed or put together
Behavioral
Behavioral design patterns define
how objects interact with one
another
Other patterns
• Module
• Callback
• Middleware
• Reactor
• Blockchain
• Scheduler
• Publisher Subscriber
14
Singleton Pattern
Ensure a class only has one instance and provide a
global point of access to it
15
Demo - Singleton
• Singleton Problem
• Class instantiates multiple objects
• Singleton Pattern solution
• Create single instance of the class throughout execution
• Singletons in node.js
• Module caching mechanism
16
Prototype Pattern
Specify the kinds of objects to create using
prototypical instance and create new objects by
copying this prototype
17
Demo - Prototype
• Prototype Problem
• Object creation is repetitive and costly
• Prototype Pattern solution
• The Clone() method
18
Factory Method Pattern
Define an interface for creating an object, but let
subclasses decide which class to instantiate. Factory
method lets a class defer instantiation to subclasses
19
Demo - Factory Method
• Factory Method problem
• Object creation with exposed logic
• Factory Method pattern solution
• Provide common interface to create new objects
20
Builder pattern
Separate the construction of a complex object from
its representation so that the same construction
process can create different representations
21
Demo - Builder
• Builder Problem
• Telescoping Constructor Anti Pattern
• Builder pattern solution
• Reduce parameters to the properties, make highly
readable method calls
22
Chain of responsibility
The GoF defines the intent of the Chain of Responsibility pattern as, to avoid
coupling the sender of a request and its receiver by giving more than one object a
chance to handle the request. Chain the receiving objects and pass the request
along the chain until an object handles it.
23
Examples?
• People
• Assembly line
• Customer service calls
• Programming
• Express middleware
24
25
27
28
29
The command pattern
The Gang of Four defines the intent the command pattern as encapsulating a
request as an object, thereby letting you parameterize clients with different
requests, queue or log requests, and support undoable operations
30
Examples?
• People
• A customer in a restaurant
• Programming
• An editor application
31
32
33
34
35
The iterator pattern
The Gang of Four defines the intent of the iterator as providing a way to access
the elements of an aggregate object (Stack, trees etc.,) sequentially without
exposing its underlying representation.
36
Examples?
• People
• A tourist without/with guides
• Programming
• Traversing in different ways on a given collection
37
38
39
40
The Observer pattern
The Gang of Four defines the intent of the observer pattern as, "Defining a one-
to-many dependency between objects so that when one object changes state, all
of its dependents are notified and updated automatically."
41
Examples?
• People
• Newsletters
• Programming
• Event based triggers, On successful transaction,
generate receipt, send payment acknowlegement email,
send receipt etc.
42
43
44
45
46
The strategy pattern
The Gang of Four defines a strategy as a family of algorithms, encapsulate each
one, and make them interchangeable. Strategy lets the algorithm vary
independently from the clients that use it.
47
Examples?
• People
• Travelling to a destination
• Programming
• Support for different payment services
• Support for different logging services
48
49
50
51
Design patterns are cool!
52
Let's learn more
about them.
Let's use them. And let's introduce
the new ones!
Topics for later talks
• Structural design patterns
• Adapter patterns
• Proxy patterns
• Composite patterns
• Decorator patterns
• Other design patterns
53
Resources
• A course by Alex Banks on LinkedIn Learning
• A course by Sachin Bhatnagar on Udemy
• https://refactoring.guru/design-patterns
• Different resourses by Mosh Hamedani
54
Thank You
55

More Related Content

What's hot

Async programming in c#
Async programming in c#Async programming in c#
Async programming in c#
Ahasanul Kalam Akib
 
Sharing our best secrets: Design a distributed system from scratch
Sharing our best secrets: Design a distributed system from scratchSharing our best secrets: Design a distributed system from scratch
Sharing our best secrets: Design a distributed system from scratch
Adelina Simion
 
Dl4j in the wild
Dl4j in the wildDl4j in the wild
Dl4j in the wild
Adam Gibson
 
Digital Forensics and Incident Response in The Cloud
Digital Forensics and Incident Response in The CloudDigital Forensics and Incident Response in The Cloud
Digital Forensics and Incident Response in The Cloud
Velocidex Enterprises
 
Tracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracing
Tracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracingTracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracing
Tracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracing
Yuri Shkuro
 
Ultralight data movement for IoT with SDC Edge. Guglielmo Iozzia - Optum
Ultralight data movement for IoT with SDC Edge. Guglielmo Iozzia - OptumUltralight data movement for IoT with SDC Edge. Guglielmo Iozzia - Optum
Ultralight data movement for IoT with SDC Edge. Guglielmo Iozzia - Optum
Data Driven Innovation
 
[WSO2Con EU 2018] Tooling for Observability
[WSO2Con EU 2018] Tooling for Observability[WSO2Con EU 2018] Tooling for Observability
[WSO2Con EU 2018] Tooling for Observability
WSO2
 
Monitoring to the Nth tier: The state of distributed tracing in 2016
Monitoring to the Nth tier: The state of distributed tracing in 2016Monitoring to the Nth tier: The state of distributed tracing in 2016
Monitoring to the Nth tier: The state of distributed tracing in 2016
AppNeta
 
Distributed tracing - get a grasp on your production
Distributed tracing - get a grasp on your productionDistributed tracing - get a grasp on your production
Distributed tracing - get a grasp on your production
nklmish
 
How to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-SourceHow to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-Source
Databricks
 
Microservices, Kafka Streams and KafkaEsque
Microservices, Kafka Streams and KafkaEsqueMicroservices, Kafka Streams and KafkaEsque
Microservices, Kafka Streams and KafkaEsque
confluent
 
What's new in Kibana - Elastic meetup
What's new in Kibana - Elastic meetupWhat's new in Kibana - Elastic meetup
What's new in Kibana - Elastic meetup
UllyCarolinneSampaio
 
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа....NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
NETFest
 
Cryptography Challenges for Computational Privacy in Public Clouds
Cryptography Challenges for Computational Privacy in Public CloudsCryptography Challenges for Computational Privacy in Public Clouds
Cryptography Challenges for Computational Privacy in Public CloudsSashank Dara
 
linkerd: The Cloud Native Service Mesh
linkerd: The Cloud Native Service Meshlinkerd: The Cloud Native Service Mesh
linkerd: The Cloud Native Service Mesh
Dario Simonetti
 
GPARS: Lessons from the parallel universe - Itamar Tayer, CoolaData
GPARS: Lessons from the parallel universe - Itamar Tayer, CoolaDataGPARS: Lessons from the parallel universe - Itamar Tayer, CoolaData
GPARS: Lessons from the parallel universe - Itamar Tayer, CoolaData
Codemotion Tel Aviv
 
stackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure driftstackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure drift
NETWAYS
 
Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...
Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...
Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...
Frank van der Linden
 
Netflix OSS Meetup Season 4 Episode 4
Netflix OSS Meetup Season 4 Episode 4Netflix OSS Meetup Season 4 Episode 4
Netflix OSS Meetup Season 4 Episode 4
aspyker
 
Anaconda and PyData Solutions
Anaconda and PyData SolutionsAnaconda and PyData Solutions
Anaconda and PyData Solutions
Travis Oliphant
 

What's hot (20)

Async programming in c#
Async programming in c#Async programming in c#
Async programming in c#
 
Sharing our best secrets: Design a distributed system from scratch
Sharing our best secrets: Design a distributed system from scratchSharing our best secrets: Design a distributed system from scratch
Sharing our best secrets: Design a distributed system from scratch
 
Dl4j in the wild
Dl4j in the wildDl4j in the wild
Dl4j in the wild
 
Digital Forensics and Incident Response in The Cloud
Digital Forensics and Incident Response in The CloudDigital Forensics and Incident Response in The Cloud
Digital Forensics and Incident Response in The Cloud
 
Tracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracing
Tracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracingTracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracing
Tracing 2000+ polyglot microservices at Uber with Jaeger and OpenTracing
 
Ultralight data movement for IoT with SDC Edge. Guglielmo Iozzia - Optum
Ultralight data movement for IoT with SDC Edge. Guglielmo Iozzia - OptumUltralight data movement for IoT with SDC Edge. Guglielmo Iozzia - Optum
Ultralight data movement for IoT with SDC Edge. Guglielmo Iozzia - Optum
 
[WSO2Con EU 2018] Tooling for Observability
[WSO2Con EU 2018] Tooling for Observability[WSO2Con EU 2018] Tooling for Observability
[WSO2Con EU 2018] Tooling for Observability
 
Monitoring to the Nth tier: The state of distributed tracing in 2016
Monitoring to the Nth tier: The state of distributed tracing in 2016Monitoring to the Nth tier: The state of distributed tracing in 2016
Monitoring to the Nth tier: The state of distributed tracing in 2016
 
Distributed tracing - get a grasp on your production
Distributed tracing - get a grasp on your productionDistributed tracing - get a grasp on your production
Distributed tracing - get a grasp on your production
 
How to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-SourceHow to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-Source
 
Microservices, Kafka Streams and KafkaEsque
Microservices, Kafka Streams and KafkaEsqueMicroservices, Kafka Streams and KafkaEsque
Microservices, Kafka Streams and KafkaEsque
 
What's new in Kibana - Elastic meetup
What's new in Kibana - Elastic meetupWhat's new in Kibana - Elastic meetup
What's new in Kibana - Elastic meetup
 
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа....NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
 
Cryptography Challenges for Computational Privacy in Public Clouds
Cryptography Challenges for Computational Privacy in Public CloudsCryptography Challenges for Computational Privacy in Public Clouds
Cryptography Challenges for Computational Privacy in Public Clouds
 
linkerd: The Cloud Native Service Mesh
linkerd: The Cloud Native Service Meshlinkerd: The Cloud Native Service Mesh
linkerd: The Cloud Native Service Mesh
 
GPARS: Lessons from the parallel universe - Itamar Tayer, CoolaData
GPARS: Lessons from the parallel universe - Itamar Tayer, CoolaDataGPARS: Lessons from the parallel universe - Itamar Tayer, CoolaData
GPARS: Lessons from the parallel universe - Itamar Tayer, CoolaData
 
stackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure driftstackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure drift
 
Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...
Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...
Wcs-1785 How Watson, Bluemix, Cloudant and XPages can work together in a real...
 
Netflix OSS Meetup Season 4 Episode 4
Netflix OSS Meetup Season 4 Episode 4Netflix OSS Meetup Season 4 Episode 4
Netflix OSS Meetup Season 4 Episode 4
 
Anaconda and PyData Solutions
Anaconda and PyData SolutionsAnaconda and PyData Solutions
Anaconda and PyData Solutions
 

Similar to Nodejs Chapter 3 - Design Pattern

Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
Julie Iskander
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
Sachin Patidar
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju1
 
Design patterns and MV
Design patterns and MVDesign patterns and MV
Design patterns and MVSway Wang
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
Rahul Singh
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Sergii Stets
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Lilia Sfaxi
 
Style & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design PatternsStyle & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design Patterns
Nick Pruehs
 
Creational Patterns
Creational PatternsCreational Patterns
Creational Patterns
Asma CHERIF
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
Asma CHERIF
 
Ds for finance day 4
Ds for finance day 4Ds for finance day 4
Ds for finance day 4
QuantUniversity
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
KadharBashaJ
 
Marco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractionMarco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractioncosenzaLab
 
Design pattern
Design patternDesign pattern
Design pattern
Mallikarjuna G D
 
Prototype design patterns
Prototype design patternsPrototype design patterns
Prototype design patterns
Thaichor Seng
 
12266422.ppt
12266422.ppt12266422.ppt
12266422.ppt
CSEC5
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Amr Abd El Latief
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?
Guillaume AGIS
 

Similar to Nodejs Chapter 3 - Design Pattern (20)

Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Design patterns and MV
Design patterns and MVDesign patterns and MV
Design patterns and MV
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Style & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design PatternsStyle & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design Patterns
 
Creational Patterns
Creational PatternsCreational Patterns
Creational Patterns
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Ds for finance day 4
Ds for finance day 4Ds for finance day 4
Ds for finance day 4
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
Marco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractionMarco Mancuso - Data Context Interaction
Marco Mancuso - Data Context Interaction
 
Design Patterns - GOF
Design Patterns - GOFDesign Patterns - GOF
Design Patterns - GOF
 
Design pattern
Design patternDesign pattern
Design pattern
 
Prototype design patterns
Prototype design patternsPrototype design patterns
Prototype design patterns
 
12266422.ppt
12266422.ppt12266422.ppt
12266422.ppt
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?
 

More from Talentica Software

Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
Talentica Software
 
Web 3.0
Web 3.0Web 3.0
Remix
RemixRemix
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
Talentica Software
 
Node js Chapter-2
Node js Chapter-2Node js Chapter-2
Node js Chapter-2
Talentica Software
 
Node.js Chapter1
Node.js Chapter1Node.js Chapter1
Node.js Chapter1
Talentica Software
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
Talentica Software
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
Talentica Software
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Talentica Software
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
Talentica Software
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discovery
Talentica Software
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging Trends
Talentica Software
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player DevelopmentTalentica Software
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
Talentica Software
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
Talentica Software
 
Big Data – Are You Ready?
Big Data – Are You Ready?Big Data – Are You Ready?
Big Data – Are You Ready?
Talentica Software
 
Legacy modernization
Legacy modernizationLegacy modernization
Legacy modernization
Talentica Software
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case Study
Talentica Software
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media Applications
Talentica Software
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application Development
Talentica Software
 

More from Talentica Software (20)

Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Web 3.0
Web 3.0Web 3.0
Web 3.0
 
Remix
RemixRemix
Remix
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
 
Node js Chapter-2
Node js Chapter-2Node js Chapter-2
Node js Chapter-2
 
Node.js Chapter1
Node.js Chapter1Node.js Chapter1
Node.js Chapter1
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discovery
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging Trends
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
 
Big Data – Are You Ready?
Big Data – Are You Ready?Big Data – Are You Ready?
Big Data – Are You Ready?
 
Legacy modernization
Legacy modernizationLegacy modernization
Legacy modernization
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case Study
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media Applications
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application Development
 

Recently uploaded

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

Nodejs Chapter 3 - Design Pattern

  • 1. NodeJS : Design Patterns 27 Feb 2021
  • 2. Acknowledgements • Organising team • O.P. Pachoriya & Sanny Kumar from Talentica. 2
  • 3. Agenda • What are design patterns? • Creational design patterns • Singleton Pattern • Prototype Pattern • Factory Method Pattern • Builder Pattern 3
  • 4. Agenda contd. • Behavioural design patterns • The chain of responsibility pattern • The command pattern • The iterator pattern • The observer pattern • The strategy pattern 4
  • 5. What should you know • Understanding of JavaScript • Some working knowledge with Node.js • Experience working in Object Oriented Programming environment 5
  • 7. OOP (A brush up) 7 f() x f() x Properties Methods Object
  • 8. 8
  • 9. OOP Benefits 9 • Encapsulation: Helps reduce complexity & promotes reusability • Abstraction: Reduces complexity & isolates impact of changes • Inheritance: Eliminates redundant code • Polymorphism: Promotes refactoring of long if/else, switch/case statements
  • 10. What are design patterns? Reusable, reliable solutions to problem that we face every day in software development 10
  • 11. Why Design Patterns? • Cataloged solutions • Reusable in many different situations • Well documented • Language for collaboration • Improve architecture • Write better program • Become a better programmer 11
  • 12. Gang of Four (GoF) • Elements of Reusable Object-Oriented Software - Gang of Four, 1994 • Design Patterns definition • Pattern name • The problem • The solution • Consequences 12
  • 13. Classical design patterns 13 Creational These patterns have to do with class instantiation, the creation of object instances in our applications Structural Structural design patterns have to do with the way objects are composed or put together Behavioral Behavioral design patterns define how objects interact with one another
  • 14. Other patterns • Module • Callback • Middleware • Reactor • Blockchain • Scheduler • Publisher Subscriber 14
  • 15. Singleton Pattern Ensure a class only has one instance and provide a global point of access to it 15
  • 16. Demo - Singleton • Singleton Problem • Class instantiates multiple objects • Singleton Pattern solution • Create single instance of the class throughout execution • Singletons in node.js • Module caching mechanism 16
  • 17. Prototype Pattern Specify the kinds of objects to create using prototypical instance and create new objects by copying this prototype 17
  • 18. Demo - Prototype • Prototype Problem • Object creation is repetitive and costly • Prototype Pattern solution • The Clone() method 18
  • 19. Factory Method Pattern Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses 19
  • 20. Demo - Factory Method • Factory Method problem • Object creation with exposed logic • Factory Method pattern solution • Provide common interface to create new objects 20
  • 21. Builder pattern Separate the construction of a complex object from its representation so that the same construction process can create different representations 21
  • 22. Demo - Builder • Builder Problem • Telescoping Constructor Anti Pattern • Builder pattern solution • Reduce parameters to the properties, make highly readable method calls 22
  • 23. Chain of responsibility The GoF defines the intent of the Chain of Responsibility pattern as, to avoid coupling the sender of a request and its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. 23
  • 24. Examples? • People • Assembly line • Customer service calls • Programming • Express middleware 24
  • 25. 25
  • 26.
  • 27. 27
  • 28. 28
  • 29. 29
  • 30. The command pattern The Gang of Four defines the intent the command pattern as encapsulating a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations 30
  • 31. Examples? • People • A customer in a restaurant • Programming • An editor application 31
  • 32. 32
  • 33. 33
  • 34. 34
  • 35. 35
  • 36. The iterator pattern The Gang of Four defines the intent of the iterator as providing a way to access the elements of an aggregate object (Stack, trees etc.,) sequentially without exposing its underlying representation. 36
  • 37. Examples? • People • A tourist without/with guides • Programming • Traversing in different ways on a given collection 37
  • 38. 38
  • 39. 39
  • 40. 40
  • 41. The Observer pattern The Gang of Four defines the intent of the observer pattern as, "Defining a one- to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically." 41
  • 42. Examples? • People • Newsletters • Programming • Event based triggers, On successful transaction, generate receipt, send payment acknowlegement email, send receipt etc. 42
  • 43. 43
  • 44. 44
  • 45. 45
  • 46. 46
  • 47. The strategy pattern The Gang of Four defines a strategy as a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it. 47
  • 48. Examples? • People • Travelling to a destination • Programming • Support for different payment services • Support for different logging services 48
  • 49. 49
  • 50. 50
  • 51. 51
  • 52. Design patterns are cool! 52 Let's learn more about them. Let's use them. And let's introduce the new ones!
  • 53. Topics for later talks • Structural design patterns • Adapter patterns • Proxy patterns • Composite patterns • Decorator patterns • Other design patterns 53
  • 54. Resources • A course by Alex Banks on LinkedIn Learning • A course by Sachin Bhatnagar on Udemy • https://refactoring.guru/design-patterns • Different resourses by Mosh Hamedani 54