SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
http://jy
aasa.comCopyright 2016. Jyaasa Technologies.
Strategy Pattern
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Ganesh Kunwar
Sr. Software Engineer
Jyaasa Technologies
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
What is Strategy Pattern?
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Ktm Butwal
Taxi Plan Taxi
Ktm.
Airport
Bhairahawa
Airport
Ktm Butwal
Taxi Bus
Kalanki
Ktm Butwal
Taxi Bus BusKalanki
Chitwan
Strategy 1
Strategy 2
Strategy 3
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Wikipedia Definition
the strategy pattern (also known as the policy pattern) is
a software design pattern that enables an algorithm's
behavior to be selected at runtime. The strategy pattern
● defines a family of algorithms,
● encapsulates each algorithm, and
● makes the algorithms interchangeable within that
family.
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
When to Use?
Shopping Mall Example
- Accept customer detail
- Calculate bill amount
- Apply discount based on the day of week
- Monday - High discount (10%)
- Friday - Low discount (5%)
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Where does the discount logic reside?
Inside ShoppingMall class
Or
Outside ShoppingMall class
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Open closed principle
- software entities (classes, modules, functions, etc.) should be open
for extension, but closed for modification
- New discount logic may be applied in future
- Not reusable - Same discount strategy can be use in other shopping
mall
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Separate discount logic from ShoppingMall class
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Context Strategy
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
=> grill = Grill.new(HotDog.new)
=> grill.grilling # => "Grilling the hot dogs!"
=> grill.food = Hamburger.new
=> grill.grilling # => "Grilling the hamburgers!"
=> grill.food = VeggiePatty.new
=> grill.grilling # => "Grilling the veggie patties!"
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
References
- https://dockyard.com/blog/2013/07/25/design-patterns-strategy-pattern
- https://en.wikipedia.org/wiki/Strategy_pattern
- https://sourcemaking.com/design_patterns/strategy
Thank you!
Lets Discuss
github.com/glunwar
@gkunwar1
Copyright 2015. Jyaasa Technologies.Copyright 2016. Jyaasa Technologies.
http://jyaasa.com

Contenu connexe

Tendances

Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
11prasoon
 

Tendances (20)

Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring
 
Visitor pattern
Visitor patternVisitor pattern
Visitor pattern
 
React Hooks
React HooksReact Hooks
React Hooks
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to Akka
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor Pattern
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation Pattern
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
Design Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract FactoryDesign Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract Factory
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
React hooks
React hooksReact hooks
React hooks
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 
Java Multithreading and Concurrency
Java Multithreading and ConcurrencyJava Multithreading and Concurrency
Java Multithreading and Concurrency
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 

Similaire à Strategy Design Pattern

Similaire à Strategy Design Pattern (20)

Welcome your new digital team member. meet your AI infused agile agent
Welcome your new digital team member. meet your AI infused agile agentWelcome your new digital team member. meet your AI infused agile agent
Welcome your new digital team member. meet your AI infused agile agent
 
Introduction to GCP (Google Cloud Platform)
Introduction to GCP (Google Cloud Platform)Introduction to GCP (Google Cloud Platform)
Introduction to GCP (Google Cloud Platform)
 
Advances in SAFe DevOps
Advances in SAFe DevOpsAdvances in SAFe DevOps
Advances in SAFe DevOps
 
Webinar: Select the Right Web CMS in 2016
Webinar: Select the Right Web CMS in 2016Webinar: Select the Right Web CMS in 2016
Webinar: Select the Right Web CMS in 2016
 
Smart Agile Tools 2020: AI taking it to the future state
Smart Agile Tools 2020: AI taking it to the future stateSmart Agile Tools 2020: AI taking it to the future state
Smart Agile Tools 2020: AI taking it to the future state
 
Machine Learning: Decision Trees
Machine Learning: Decision TreesMachine Learning: Decision Trees
Machine Learning: Decision Trees
 
Industrial Transformation
Industrial TransformationIndustrial Transformation
Industrial Transformation
 
Analytics Store for Hybrid Cloud
Analytics Store for Hybrid CloudAnalytics Store for Hybrid Cloud
Analytics Store for Hybrid Cloud
 
Machine learning & computer vision
Machine learning & computer visionMachine learning & computer vision
Machine learning & computer vision
 
Machine Learning in Computer Vision
Machine Learning in Computer VisionMachine Learning in Computer Vision
Machine Learning in Computer Vision
 
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
 
Cwin16 tls-partner-sas new-open_analytics_platform
Cwin16 tls-partner-sas new-open_analytics_platformCwin16 tls-partner-sas new-open_analytics_platform
Cwin16 tls-partner-sas new-open_analytics_platform
 
What, Why and How of Governance in RPA
What, Why and How of Governance  in RPAWhat, Why and How of Governance  in RPA
What, Why and How of Governance in RPA
 
The Future of AI on AWS
The Future of AI on AWSThe Future of AI on AWS
The Future of AI on AWS
 
Just add Imagination
Just add ImaginationJust add Imagination
Just add Imagination
 
MLops workshop AWS
MLops workshop AWSMLops workshop AWS
MLops workshop AWS
 
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
 
Microservices: The Building Blocks for a Digital Future
Microservices: The Building Blocks for a Digital FutureMicroservices: The Building Blocks for a Digital Future
Microservices: The Building Blocks for a Digital Future
 
Trends and Best Practices for Implementing SaaS for Your Business
Trends and Best Practices for Implementing SaaS for Your BusinessTrends and Best Practices for Implementing SaaS for Your Business
Trends and Best Practices for Implementing SaaS for Your Business
 
Grassroots Kanban – An Evolutionary Approach To Change
Grassroots Kanban – An Evolutionary Approach To ChangeGrassroots Kanban – An Evolutionary Approach To Change
Grassroots Kanban – An Evolutionary Approach To Change
 

Plus de Jyaasa Technologies

Plus de Jyaasa Technologies (20)

Incident management with jira
Incident management with jiraIncident management with jira
Incident management with jira
 
Extreme programming practices ( xp )
Extreme programming practices ( xp ) Extreme programming practices ( xp )
Extreme programming practices ( xp )
 
The myth of 'real javascript developer'
The myth of 'real javascript developer'The myth of 'real javascript developer'
The myth of 'real javascript developer'
 
Microservices
MicroservicesMicroservices
Microservices
 
Facade pattern in rails
Facade pattern in railsFacade pattern in rails
Facade pattern in rails
 
Scrum ceromonies
Scrum ceromoniesScrum ceromonies
Scrum ceromonies
 
An introduction to bitcoin
An introduction to bitcoinAn introduction to bitcoin
An introduction to bitcoin
 
Tor network
Tor networkTor network
Tor network
 
Collective ownership in agile teams
Collective ownership in agile teamsCollective ownership in agile teams
Collective ownership in agile teams
 
Push notification
Push notificationPush notification
Push notification
 
The Design Thinking Process
The Design Thinking ProcessThe Design Thinking Process
The Design Thinking Process
 
User story
User storyUser story
User story
 
Design sprint
Design sprintDesign sprint
Design sprint
 
Data Flow Diagram
Data Flow DiagramData Flow Diagram
Data Flow Diagram
 
OKRs and Actions Overview
OKRs and Actions OverviewOKRs and Actions Overview
OKRs and Actions Overview
 
Vue.js
Vue.jsVue.js
Vue.js
 
Active record in rails 5
Active record in rails 5Active record in rails 5
Active record in rails 5
 
Design Patern::Adaptor pattern
Design Patern::Adaptor patternDesign Patern::Adaptor pattern
Design Patern::Adaptor pattern
 
Association in rails
Association in railsAssociation in rails
Association in rails
 
Web design layout pattern
Web design layout patternWeb design layout pattern
Web design layout pattern
 

Dernier

+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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Dernier (20)

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
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 🔝✔️✔️
 
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
 
+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...
 
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
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.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...
 
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
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
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 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.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
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
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
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 

Strategy Design Pattern

  • 1. http://jy aasa.comCopyright 2016. Jyaasa Technologies. Strategy Pattern
  • 2. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Ganesh Kunwar Sr. Software Engineer Jyaasa Technologies
  • 3. Copyright 2016. Jyaasa Technologies. http://jy aasa.com What is Strategy Pattern?
  • 4. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  • 5. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Ktm Butwal Taxi Plan Taxi Ktm. Airport Bhairahawa Airport Ktm Butwal Taxi Bus Kalanki Ktm Butwal Taxi Bus BusKalanki Chitwan Strategy 1 Strategy 2 Strategy 3
  • 6. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Wikipedia Definition the strategy pattern (also known as the policy pattern) is a software design pattern that enables an algorithm's behavior to be selected at runtime. The strategy pattern ● defines a family of algorithms, ● encapsulates each algorithm, and ● makes the algorithms interchangeable within that family.
  • 7. Copyright 2016. Jyaasa Technologies. http://jy aasa.com When to Use? Shopping Mall Example - Accept customer detail - Calculate bill amount - Apply discount based on the day of week - Monday - High discount (10%) - Friday - Low discount (5%)
  • 8. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Where does the discount logic reside? Inside ShoppingMall class Or Outside ShoppingMall class
  • 9. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  • 10. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Open closed principle - software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification - New discount logic may be applied in future - Not reusable - Same discount strategy can be use in other shopping mall
  • 11. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Separate discount logic from ShoppingMall class
  • 12. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Context Strategy
  • 13. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  • 14. Copyright 2016. Jyaasa Technologies. http://jy aasa.com => grill = Grill.new(HotDog.new) => grill.grilling # => "Grilling the hot dogs!" => grill.food = Hamburger.new => grill.grilling # => "Grilling the hamburgers!" => grill.food = VeggiePatty.new => grill.grilling # => "Grilling the veggie patties!"
  • 15. Copyright 2016. Jyaasa Technologies. http://jy aasa.com References - https://dockyard.com/blog/2013/07/25/design-patterns-strategy-pattern - https://en.wikipedia.org/wiki/Strategy_pattern - https://sourcemaking.com/design_patterns/strategy
  • 16. Thank you! Lets Discuss github.com/glunwar @gkunwar1 Copyright 2015. Jyaasa Technologies.Copyright 2016. Jyaasa Technologies. http://jyaasa.com